File size: 3,467 Bytes
3033f6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2ccf148
3033f6b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
---
tags:
- bert
- transformers
- litert
- tflite
- edge
- on-device
license: mit
base_model: FacebookAI/roberta-base
pipeline_tag: feature-extraction
---

# roberta-base - LiteRT

This is a [LiteRT](https://ai.google.dev/edge/litert) (formerly TensorFlow Lite) conversion of [FacebookAI/roberta-base](https://huggingface.co/FacebookAI/roberta-base) for efficient on-device inference.

## Model Details

| Property | Value |
|----------|-------|
| **Original Model** | [FacebookAI/roberta-base](https://huggingface.co/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) |

## Performance

Benchmarked on AMD CPU (WSL2):

| Metric | Value |
|--------|-------|
| **Inference Latency** | 81.2 ms |
| **Throughput** | 12.3/sec |
| **Cosine Similarity vs Original** | 1.0000 ✅ |

## Quick Start

```python
import numpy as np
from ai_edge_litert.interpreter import Interpreter
from transformers import AutoTokenizer

# Load model and tokenizer
interpreter = Interpreter(model_path="FacebookAI_roberta-base.tflite")
interpreter.allocate_tensors()
input_details = interpreter.get_input_details()
output_details = interpreter.get_output_details()

tokenizer = AutoTokenizer.from_pretrained("FacebookAI/roberta-base")

def get_hidden_states(text: str) -> np.ndarray:
    """Get hidden states for input text."""
    encoded = tokenizer(
        text,
        padding="max_length",
        max_length=128,
        truncation=True,
        return_tensors="np"
    )

    interpreter.set_tensor(input_details[0]["index"], encoded["input_ids"].astype(np.int64))
    interpreter.set_tensor(input_details[1]["index"], encoded["attention_mask"].astype(np.int64))
    interpreter.invoke()

    return interpreter.get_tensor(output_details[0]["index"])

# Example
hidden = get_hidden_states("Hello, world!")
cls_embedding = hidden[0, 0, :]  # CLS token for classification
print(f"Hidden shape: {hidden.shape}")  # (1, 128, 768)
```

## Files

- `FacebookAI_roberta-base.tflite` - The LiteRT model file

## Conversion Details

- **Conversion Tool**: [ai-edge-torch](https://github.com/google-ai-edge/ai-edge-torch)
- **Conversion Date**: 2026-01-12
- **Source Framework**: PyTorch → LiteRT
- **Validation**: Cosine similarity 1.0000 vs original

## Intended Use

- **Mobile Applications**: On-device semantic search, RAG systems
- **Edge Devices**: IoT, embedded systems, Raspberry Pi
- **Offline Processing**: Privacy-preserving inference
- **Low-latency Applications**: Real-time processing

## Limitations

- Fixed sequence length (128 tokens)
- CPU inference (GPU delegate requires setup)
- Tokenizer loaded separately from original model
- Float32 precision

## License

This model inherits the license from the original:
- **License**: MIT ([source](https://huggingface.co/FacebookAI/roberta-base))

## Citation

```bibtex
@article{liu2019roberta,
    title={RoBERTa: A Robustly Optimized BERT Pretraining Approach},
    author={Liu, Yinhan and Ott, Myle and others},
    journal={arXiv preprint arXiv:1907.11692},
    year={2019}
}
```

## Acknowledgments

- Original model by [FacebookAI](https://huggingface.co/FacebookAI)
- Conversion using [ai-edge-torch](https://github.com/google-ai-edge/ai-edge-torch)

---

*Converted by [Bombek1](https://huggingface.co/Bombek1)*