(example: Dict[str, Any])
| 184 | examples = [{'input_ids': example} for example in examples] |
| 185 | |
| 186 | def tensorize(example: Dict[str, Any]) -> Dict[str, Any]: |
| 187 | tensorized = {} |
| 188 | for key in ['input_ids', 'offsets']: |
| 189 | if key not in example: |
| 190 | continue |
| 191 | if isinstance(example[key], List): |
| 192 | tensorized[key] = torch.tensor(example[key], dtype=torch.long) |
| 193 | elif isinstance(example[key], np.ndarray): |
| 194 | tensorized[key] = torch.from_numpy(example[key]) |
| 195 | else: |
| 196 | tensorized[key] = example[key] |
| 197 | return tensorized |
| 198 | |
| 199 | examples = list(map(tensorize, examples)) |
| 200 |
nothing calls this directly
no outgoing calls
no test coverage detected