HuggingFaceCrossEncoder#

class langchain_community.cross_encoders.huggingface.HuggingFaceCrossEncoder[source]#

Bases: BaseModel, BaseCrossEncoder

HuggingFace cross encoder models.

Example

from langchain_community.cross_encoders import HuggingFaceCrossEncoder

model_name = "BAAI/bge-reranker-base"
model_kwargs = {'device': 'cpu'}
hf = HuggingFaceCrossEncoder(
    model_name=model_name,
    model_kwargs=model_kwargs
)

Initialize the sentence_transformer.

param model_kwargs: Dict[str, Any] [Optional]#

Keyword arguments to pass to the model.

param model_name: str = 'BAAI/bge-reranker-base'#

Model name to use.

score(text_pairs: List[Tuple[str, str]]) List[float][source]#

Compute similarity scores using a HuggingFace transformer model.

Parameters:

text_pairs (List[Tuple[str, str]]) – The list of text text_pairs to score the similarity.

Returns:

List of scores, one for each pair.

Return type:

List[float]

Examples using HuggingFaceCrossEncoder