Class: Informers::Model
- Inherits:
-
Object
- Object
- Informers::Model
- Defined in:
- lib/informers/model.rb
Instance Method Summary collapse
- #embed(texts) ⇒ Object
-
#initialize(model_id, quantized: false) ⇒ Model
constructor
A new instance of Model.
Constructor Details
#initialize(model_id, quantized: false) ⇒ Model
Returns a new instance of Model.
3 4 5 6 7 8 9 10 11 |
# File 'lib/informers/model.rb', line 3 def initialize(model_id, quantized: false) @model_id = model_id @model = Informers.pipeline("feature-extraction", model_id, quantized: quantized) # TODO better pattern if model_id == "sentence-transformers/all-MiniLM-L6-v2" @model.instance_variable_get(:@model).instance_variable_set(:@output_names, ["sentence_embedding"]) end end |
Instance Method Details
#embed(texts) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/informers/model.rb', line 13 def (texts) is_batched = texts.is_a?(Array) texts = [texts] unless is_batched case @model_id when "sentence-transformers/all-MiniLM-L6-v2" output = @model.(texts) when "Xenova/all-MiniLM-L6-v2", "Xenova/multi-qa-MiniLM-L6-cos-v1", "Supabase/gte-small" output = @model.(texts, pooling: "mean", normalize: true) when "mixedbread-ai/mxbai-embed-large-v1" output = @model.(texts, pooling: "cls") else raise Error, "model not supported: #{@model_id}" end is_batched ? output : output[0] end |