Class: Candle::Reranker
- Inherits:
-
Object
- Object
- Candle::Reranker
- Defined in:
- lib/candle/reranker.rb
Constant Summary collapse
- DEFAULT_MODEL_PATH =
Default model path for cross-encoder/ms-marco-MiniLM-L-12-v2
"cross-encoder/ms-marco-MiniLM-L-12-v2"
Class Method Summary collapse
-
.new(model_path: DEFAULT_MODEL_PATH, device: Candle::Device.cpu) ⇒ Object
Constructor for creating a new Reranker with optional parameters.
Instance Method Summary collapse
-
#rerank(query, documents, pooling_method: "pooler", apply_sigmoid: true) ⇒ Object
Returns documents ranked by relevance using the specified pooling method.
Class Method Details
.new(model_path: DEFAULT_MODEL_PATH, device: Candle::Device.cpu) ⇒ Object
Constructor for creating a new Reranker with optional parameters
9 10 11 |
# File 'lib/candle/reranker.rb', line 9 def self.new(model_path: DEFAULT_MODEL_PATH, device: Candle::Device.cpu) _create(model_path, device) end |
Instance Method Details
#rerank(query, documents, pooling_method: "pooler", apply_sigmoid: true) ⇒ Object
Returns documents ranked by relevance using the specified pooling method.
18 19 20 21 22 |
# File 'lib/candle/reranker.rb', line 18 def rerank(query, documents, pooling_method: "pooler", apply_sigmoid: true) (query, documents, pooling_method, apply_sigmoid).collect { |doc, score, doc_id| { doc_id: doc_id, score: score, text: doc } } end |