or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

async-inference.mdchat-completions.mdconfiguration.mdindex.mdparameters-types.mdtext-classification.mdtext-embeddings.mdtext-generation.mdtext-scoring.md

text-scoring.mddocs/

0

# Text Scoring

1

2

Text similarity and likelihood scoring for comparing text pairs, ranking, and evaluation tasks. Supports various scoring methods including cosine similarity and likelihood-based metrics.

3

4

## Capabilities

5

6

### Text Scoring

7

8

Compare text pairs and compute similarity or likelihood scores for ranking, retrieval, and evaluation applications.

9

10

```python { .api }

11

def score(

12

self,

13

data_1: Union[SingletonPrompt, Sequence[SingletonPrompt], ScoreMultiModalParam],

14

data_2: Union[SingletonPrompt, Sequence[SingletonPrompt], ScoreMultiModalParam],

15

/,

16

*,

17

truncate_prompt_tokens: Optional[int] = None,

18

use_tqdm: Union[bool, Callable[..., tqdm]] = True,

19

pooling_params: Optional[PoolingParams] = None,

20

lora_request: Optional[Union[List[LoRARequest], LoRARequest]] = None

21

) -> List[ScoringRequestOutput]:

22

"""

23

Score similarity between text pairs.

24

25

Parameters:

26

- data_1: First set of texts (positional-only)

27

- data_2: Second set of texts to compare (positional-only)

28

- truncate_prompt_tokens: Maximum prompt length (keyword-only)

29

- use_tqdm: Show progress bar (keyword-only)

30

- pooling_params: Pooling configuration for embeddings (keyword-only)

31

- lora_request: LoRA adapter configuration (keyword-only)

32

33

Returns:

34

List of ScoringRequestOutput with similarity scores

35

36

Note: The scoring method is automatically determined by the model type.

37

Embedding models use cosine similarity, cross-encoder models use likelihood.

38

"""

39

```

40

41

## Usage Examples

42

43

### Text Similarity Scoring

44

45

```python

46

from vllm import LLM, PoolingParams

47

48

llm = LLM(model="sentence-transformers/all-MiniLM-L6-v2")

49

50

text_pairs = [

51

("The cat sat on the mat.", "A cat was sitting on a mat."),

52

("Python is a programming language.", "Java is a programming language."),

53

("I love pizza.", "Pizza is the worst food ever.")

54

]

55

56

pooling_params = PoolingParams(pooling_type="MEAN", normalize=True)

57

58

for text1, text2 in text_pairs:

59

outputs = llm.score(

60

[text1], [text2],

61

kind="cosine_similarity",

62

pooling_params=pooling_params

63

)

64

score = outputs[0].outputs.score

65

print(f"Similarity: {score:.3f} - '{text1}' vs '{text2}'")

66

```

67

68

## Types

69

70

```python { .api }

71

class ScoringRequestOutput:

72

id: str

73

outputs: ScoringOutput

74

prompt_token_ids: List[int]

75

finished: bool

76

77

class ScoringOutput:

78

score: float # Similarity or likelihood score

79

```