logo
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Readme
Files and versions

Updated 3 years ago

text-embedding

Text Embedding with Transformers

author: Jael Gu and David Wang

Desription

A REALM[1] text embedding operator implemented with pretrained models from Huggingface Transformers.

from towhee import ops

text_encoder = ops.text_embedding.realm('google/realm-cc-news-pretrained-encoder')
text_embedding = text_encoder("Hello, world.")

Factory Constructor

Create the operator via the following factory method

ops.text_embedding.realm(model_name)

Interface

A text embedding operator takes a sentence, paragraph, or document in string as an input and output an embedding vector in ndarray which captures the input's core semantic elements.

Parameters:

text: str

​ The text in string.

Returns: numpy.ndarray

​ The text embedding extracted by model.

Code Example

Use the pretrained model ('google/realm-cc-news-pretrained-encoder') to generate a text embedding for the sentence "Hello, world.".

Write the pipeline in simplified style:

import towhee.DataCollection as dc

dc.glob("Hello, world.")
  .text_embedding.realm('google/realm-cc-news-pretrained-encoder')
  .show()

Write a same pipeline with explicit inputs/outputs name specifications:

from towhee import DataCollection as dc

dc.glob['text']('Hello, world.')
  .text_embedding.realm['text', 'vec']('bert-base-cased')
  .select('vec')
  .show()

[1] https://arxiv.org/abs/2002.08909

wxywb 2120bdc191 add the reference. 3 Commits
file-icon .gitattributes
1.1 KiB
download-icon
Initial commit 3 years ago
file-icon README.md
1.5 KiB
download-icon
add the reference. 3 years ago
file-icon __init__.py
677 B
download-icon
init the repo. 3 years ago
file-icon realm.py
2.3 KiB
download-icon
init the repo. 3 years ago
file-icon requirements.txt
42 B
download-icon
init the repo. 3 years ago