Views
No views yet
| Attribute | Value |
|---|---|
| Task | Ultra-Fast Reranking |
| Format | .tflite (Float32) |
| File Size | 16.8 MB |
| Input Length | 512 tokens |
| Output Dim | 1 |
1import numpy as np
2from ai_edge_litert.interpreter import Interpreter
3from transformers import AutoTokenizer
4
5model_path = "cross-encoder_ms-marco-TinyBERT-L-2-v2.tflite"
6interpreter = Interpreter(model_path=model_path)
7interpreter.allocate_tensors()
8
9tokenizer = AutoTokenizer.from_pretrained("cross-encoder/ms-marco-TinyBERT-L-2-v2")
10
11def compute_score(query, doc):
12 # Tokenize Pair: [CLS] query [SEP] doc [SEP]
13 inputs = tokenizer(query, doc, max_length=512, padding="max_length", truncation=True, return_tensors="np")
14
15 input_details = interpreter.get_input_details()
16 interpreter.set_tensor(input_details[0]['index'], inputs['input_ids'].astype(np.int64))
17 interpreter.set_tensor(input_details[1]['index'], inputs['attention_mask'].astype(np.int64))
18
19 interpreter.invoke()
20
21 # Output is a single score (logit)
22 output_details = interpreter.get_output_details()
23 score = interpreter.get_tensor(output_details[0]['index'])[0][0]
24 return score
25
26score = compute_score("What is python?", "Python is a programming language.")
27print(f"Relevance Score: {score}")