Class: Transformers::SentenceTransformer
- Inherits:
-
Object
- Object
- Transformers::SentenceTransformer
- Defined in:
- lib/transformers/sentence_transformer.rb
Overview
TODO remove in 0.2.0
Instance Method Summary collapse
- #encode(sentences) ⇒ Object
-
#initialize(model_id) ⇒ SentenceTransformer
constructor
A new instance of SentenceTransformer.
Constructor Details
#initialize(model_id) ⇒ SentenceTransformer
Returns a new instance of SentenceTransformer.
4 5 6 7 |
# File 'lib/transformers/sentence_transformer.rb', line 4 def initialize(model_id) @model_id = model_id @model = Transformers.pipeline("embedding", model_id) end |
Instance Method Details
#encode(sentences) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/transformers/sentence_transformer.rb', line 9 def encode(sentences) # TODO check modules.json if [ "sentence-transformers/all-MiniLM-L6-v2", "sentence-transformers/multi-qa-MiniLM-L6-cos-v1" ].include?(@model_id) @model.(sentences) else @model.(sentences, pooling: "cls", normalize: false) end end |