{"record":{"id":"d674757e4c1f43ee","repo":"hankcs/HanLP","slug":"not-supported","errorCode":null,"errorMessage":"Not supported.","messagePattern":"Not supported\\.","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"hanlp/layers/embeddings/fast_text.py","lineNumber":113,"sourceCode":"            src: Field name.\n            filepath: Filepath to pretrained fastText embeddings.\n        \"\"\"\n        super().__init__()\n        self.src = src\n        self.filepath = filepath\n        self._fasttext = FastTextTransform(self.filepath, self.src)\n\n    def transform(self, **kwargs) -> Optional[Callable]:\n        return self._fasttext\n\n    def module(self, **kwargs) -> Optional[nn.Module]:\n        return FastTextEmbeddingModule(self._fasttext.dst, self._fasttext.output_dim)\n\n\nclass FastTextDataset(TransformableDataset):\n\n    def load_file(self, filepath: str):\n        raise NotImplementedError('Not supported.')\n\n\nclass FastTextEmbeddingComponent(TorchComponent):\n    def __init__(self, **kwargs) -> None:\n        \"\"\" Toy example of Word2VecEmbedding. It simply returns the embedding of a given word\n\n        Args:\n            **kwargs:\n        \"\"\"\n        super().__init__(**kwargs)\n\n    def build_dataloader(self, data, shuffle=False, device=None, logger: logging.Logger = None,\n                         **kwargs) -> DataLoader:\n        embed: FastTextEmbedding = self.config.embed\n        dataset = FastTextDataset([{'token': data}], transform=embed.transform())\n        return PadSequenceDataLoader(dataset, device=device)\n\n    def build_optimizer(self, **kwargs):","sourceCodeStart":95,"sourceCodeEnd":131,"githubUrl":"https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/fast_text.py#L95-L131","documentation":"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.","triggerScenarios":"Instantiating FastTextDataset and calling .load_file(path), or configuring a pipeline that tries to load training samples from a file into this dataset class.","commonSituations":"Trying to train fastText embeddings inside HanLP; reusing the dataset class as a generic token dataset and passing a filename.","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"],"exampleFix":"# before\nds = FastTextDataset(['train.txt'])  # triggers load_file -> error\n# after\nds = FastTextDataset([{'token': tokens}], transform=ft_embed.transform())","handlingStrategy":"type-guard","validationCode":"assert isinstance(data, list) and not isinstance(data, str), 'pass in-memory token lists, not file paths'","typeGuard":"def is_inmemory_data(data) -> bool:\n    return isinstance(data, (list, tuple)) and not any(isinstance(d, str) and d.endswith('.txt') for d in data)","tryCatchPattern":null,"preventionTips":["Read files yourself and pass token lists","Reserve this dataset for embedding lookup only"],"tags":["hanlp","fasttext","dataset","not-implemented"],"backgroundTag":"unsupported-operation","analyzedSha":"ddb1299bddff079e447af52ec12549c50636bfa8","analyzedAt":"2026-08-27T03:36:54.287Z","schemaVersion":2},"datasetVersion":"2026-08-27T08:17:20.692Z"}