mirror of
https://github.com/hwchase17/langchain
synced 2024-11-10 01:10:59 +00:00
f98d7f7494
- **Description:** Support reranking based on cross encoder models available from HuggingFace. - Added `CrossEncoder` schema - Implemented `HuggingFaceCrossEncoder` and `SagemakerEndpointCrossEncoder` - Implemented `CrossEncoderReranker` that performs similar functionality to `CohereRerank` - Added `cross-encoder-reranker.ipynb` to demonstrate how to use it. Please let me know if anything else needs to be done to make it visible on the table-of-contents navigation bar on the left, or on the card list on [retrievers documentation page](https://python.langchain.com/docs/integrations/retrievers). - **Issue:** N/A - **Dependencies:** None other than the existing ones. --------- Co-authored-by: Kenny Choe <kchoe@amazon.com> Co-authored-by: Bagatur <baskaryan@gmail.com>
18 lines
393 B
Python
18 lines
393 B
Python
from abc import ABC, abstractmethod
|
|
from typing import List, Tuple
|
|
|
|
|
|
class BaseCrossEncoder(ABC):
|
|
"""Interface for cross encoder models."""
|
|
|
|
@abstractmethod
|
|
def score(self, text_pairs: List[Tuple[str, str]]) -> List[float]:
|
|
"""Score pairs' similarity.
|
|
|
|
Args:
|
|
text_pairs: List of pairs of texts.
|
|
|
|
Returns:
|
|
List of scores.
|
|
"""
|