Browse Source
Update
Signed-off-by: Jael Gu <mengjia.gu@zilliz.com>
main
3 changed files with
11 additions and
4 deletions
-
README.md
-
dpr.py
-
BIN
result.png
|
|
@ -33,12 +33,19 @@ to generate a text embedding for the sentence "Hello, world.". |
|
|
|
*Write the pipeline*: |
|
|
|
|
|
|
|
```python |
|
|
|
import towhee |
|
|
|
from towhee.dc2 import pipe, ops, DataCollection |
|
|
|
|
|
|
|
towhee.dc(["Hello, world."]) \ |
|
|
|
.text_embedding.dpr(model_name="facebook/dpr-ctx_encoder-single-nq-base") |
|
|
|
p = ( |
|
|
|
pipe.input('text') |
|
|
|
.map('text', 'vec', ops.text_embedding.dpr(model_name='facebook/dpr-ctx_encoder-single-nq-base')) |
|
|
|
.output('text', 'vec') |
|
|
|
) |
|
|
|
|
|
|
|
DataCollection(p('Hello, world.')).show() |
|
|
|
``` |
|
|
|
|
|
|
|
<img src="./result.png" width="800px"/> |
|
|
|
|
|
|
|
<br /> |
|
|
|
|
|
|
|
## Factory Constructor |
|
|
|
|
|
@ -50,7 +50,7 @@ class Dpr(NNOperator): |
|
|
|
except Exception as e: |
|
|
|
log.error(f'Invalid input for the model: {self.model_name}') |
|
|
|
raise e |
|
|
|
vec = embeddings.detach().numpy() |
|
|
|
vec = embeddings.squeeze(0).detach().numpy() |
|
|
|
return vec |
|
|
|
|
|
|
|
|
|
|
|
Width:
|
Height:
|
Size: 5.6 KiB
|