hankcs/HanLP · error · NotImplementedError
Not supported.
Error message
Not supported.
What it means
FastTextDataset.load_file is explicitly NotImplementedError because FastText embeddings in HanLP are loaded from a pretrained .bin/vector file via the FastTextEmbedding module, not from an arbitrary corpus file. The dataset only exists to transform in-memory token lists handed to it by build_dataloader; calling load_file directly (or pointing the component at a file path to read as samples) is unsupported.
Source
Thrown at hanlp/layers/embeddings/fast_text.py:113
src: Field name.
filepath: Filepath to pretrained fastText embeddings.
"""
super().__init__()
self.src = src
self.filepath = filepath
self._fasttext = FastTextTransform(self.filepath, self.src)
def transform(self, **kwargs) -> Optional[Callable]:
return self._fasttext
def module(self, **kwargs) -> Optional[nn.Module]:
return FastTextEmbeddingModule(self._fasttext.dst, self._fasttext.output_dim)
class FastTextDataset(TransformableDataset):
def load_file(self, filepath: str):
raise NotImplementedError('Not supported.')
class FastTextEmbeddingComponent(TorchComponent):
def __init__(self, **kwargs) -> None:
""" Toy example of Word2VecEmbedding. It simply returns the embedding of a given word
Args:
**kwargs:
"""
super().__init__(**kwargs)
def build_dataloader(self, data, shuffle=False, device=None, logger: logging.Logger = None,
**kwargs) -> DataLoader:
embed: FastTextEmbedding = self.config.embed
dataset = FastTextDataset([{'token': data}], transform=embed.transform())
return PadSequenceDataLoader(dataset, device=device)
def build_optimizer(self, **kwargs):View on GitHub (pinned to ddb1299bdd)
Solutions
- Don't use FastTextDataset to read files; construct it with in-memory data like FastTextDataset([{'token': data}], transform=...)
- Load fastText vectors via the FastTextEmbedding config instead
- Subclass TransformableDataset and implement load_file if you need file loading
Example fix
# before
ds = FastTextDataset(['train.txt']) # triggers load_file -> error
# after
ds = FastTextDataset([{'token': tokens}], transform=ft_embed.transform()) Defensive patterns
Strategy: type-guard
Validate before calling
assert isinstance(data, list) and not isinstance(data, str), 'pass in-memory token lists, not file paths'
Type guard
def is_inmemory_data(data) -> bool:
return isinstance(data, (list, tuple)) and not any(isinstance(d, str) and d.endswith('.txt') for d in data) Prevention
- Read files yourself and pass token lists
- Reserve this dataset for embedding lookup only
When it happens
Trigger: Instantiating FastTextDataset and calling .load_file(path), or configuring a pipeline that tries to load training samples from a file into this dataset class.
Common situations: Trying to train fastText embeddings inside HanLP; reusing the dataset class as a generic token dataset and passing a filename.
Understand the failure class
Background: UnsupportedOperationException and "is not supported" errors: when a library deliberately refuses a call — this error's family across 30 libraries.
Related errors
- Not supported.
- error
- output ({}) must be of type bool or str
- Call fit or load before evaluate.
- Unrecognized devices {devices}
AI-assisted analysis of hankcs/HanLP@ddb1299bdd (2026-08-27).
Data as JSON: /api/errors/d674757e4c1f43ee.
Report an issue: GitHub.