Skip to main content
Word segmentation (myword and CRF engines) requires binary resources, specifically a dictionary file and a CRF model, that are too large to bundle with the pip package. They download from HuggingFace on first use and are cached locally. This page explains how the cache works, how to pre-populate it for offline or airgapped deployments, and how to point it at a custom directory.

Overview

Available Resources

Resource Resolution

Resources are resolved in this order:
  1. Local bundled path: Check if package includes the file
  2. Cache directory: Check previously downloaded files
  3. Download: Fetch from HuggingFace on first use

Core Functions

get_resource_path

General-purpose resource getter:

Convenience Functions

Specific getters for each resource:

Downloading All Resources

To pre-download all resources, call each getter:

Cache Locations

Default Cache Directory

Local Bundled Paths

Resources can be bundled with the package:
myspellchecker
data
models
segmentation.mmap
wordseg_c2_crf.crfsuite
If files exist locally, they’re used instead of downloading.

HuggingFace Integration

Resources are hosted on HuggingFace Datasets:

Download Behavior

First Use

Subsequent Uses

Skip Bundled Resources

Error Handling

Unknown Resource

Download Failure

Network Issues

The loader handles network failures gracefully:

Integration Examples

With DefaultSegmenter

With CRF Tokenizer

Offline Mode

Pre-download resources for offline use:

Configuration

Environment Variables

Custom Cache Directory

ResourceConfig

The ResourceConfig class provides a Pydantic model for configuring resource download and caching behavior. It controls the HuggingFace repository URL, version tag, and local cache directory.

Airgapped / Offline Deployments

For environments without internet access, pre-download resources on a connected machine and point cache_dir to the local path:
Alternatively, set the environment variable to redirect all resource lookups:

Best Practices

1. Pre-download in Production

2. Use Custom Cache for Containers

3. Handle Network Failures

4. Update Cached Resources

See Also