Views
No views yet
| Property | Value |
|---|---|
| Original Model | google/electra-small-discriminator |
| Format | LiteRT (.tflite) |
| File Size | 52.0 MB |
| Task | Feature Extraction / Classification Base |
| Max Sequence Length | 128 |
| Output Dimension | 256 |
| Pooling Mode | N/A (Full hidden states) |
| Metric | Value |
|---|---|
| Inference Latency | 9.3 ms |
| Throughput | 107.5 tokens/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="google_electra-small-discriminator.tflite")
7interpreter.allocate_tensors()
8input_details = interpreter.get_input_details()
9output_details = interpreter.get_output_details()
10
11tokenizer = AutoTokenizer.from_pretrained("google/electra-small-discriminator")
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, 256)google_electra-small-discriminator.tflite - The LiteRT model file1@article{clark2020electra,
2 title={ELECTRA: Pre-training Text Encoders as Discriminators Rather Than Generators},
3 author={Clark, Kevin and Luong, Minh-Thang and Le, Quoc V and Manning, Christopher D},
4 journal={arXiv preprint arXiv:2003.10555},
5 year={2020}
6}