Views
No views yet
| Property | Value |
|---|---|
| Original Model | FacebookAI/roberta-base |
| Format | LiteRT (.tflite) |
| File Size | 473.7 MB |
| Task | Feature Extraction / Classification Base |
| Max Sequence Length | 128 |
| Output Dimension | 768 |
| Pooling Mode | N/A (Full hidden states) |
| Metric | Value |
|---|---|
| Inference Latency | 81.2 ms |
| Throughput | 12.3/sec |
| Cosine Similarity vs Original | 1.0000 ✅ |
1import numpy as np
2from ai_edge_litert.interpreter import Interpreter
3from transformers import AutoTokenizer
4
5# Load model and tokenizer
6interpreter = Interpreter(model_path="FacebookAI_roberta-base.tflite")
7interpreter.allocate_tensors()
8input_details = interpreter.get_input_details()
9output_details = interpreter.get_output_details()
10
11tokenizer = AutoTokenizer.from_pretrained("FacebookAI/roberta-base")
12
13def get_hidden_states(text: str) -> np.ndarray:
14 """Get hidden states for input text."""
15 encoded = tokenizer(
16 text,
17 padding="max_length",
18 max_length=128,
19 truncation=True,
20 return_tensors="np"
21 )
22
23 interpreter.set_tensor(input_details[0]["index"], encoded["input_ids"].astype(np.int64))
24 interpreter.set_tensor(input_details[1]["index"], encoded["attention_mask"].astype(np.int64))
25 interpreter.invoke()
26
27 return interpreter.get_tensor(output_details[0]["index"])
28
29# Example
30hidden = get_hidden_states("Hello, world!")
31cls_embedding = hidden[0, 0, :] # CLS token for classification
32print(f"Hidden shape: {hidden.shape}") # (1, 128, 768)FacebookAI_roberta-base.tflite - The LiteRT model file1@article{liu2019roberta,
2 title={RoBERTa: A Robustly Optimized BERT Pretraining Approach},
3 author={Liu, Yinhan and Ott, Myle and others},
4 journal={arXiv preprint arXiv:1907.11692},
5 year={2019}
6}