richtext/foodmapper-gte-large
FoodMapper GTE-Large (MLX Format)
This is thenlper/gte-large revision 4bef63f39fcc5e2d6b0aae83089f307af4970164, converted to MLX-Swift safetensors format for the FoodMapper macOS application.
Model Description
GTE-Large is a 335M parameter text embedding model that maps sentences to 1024-dimensional dense vectors. FoodMapper uses this conversion for food-description retrieval.
The converted weights use the safetensors format loaded by MLX-Swift on Apple Silicon.
Intended Use
- Semantic food name matching (e.g., matching "granny smith apple" to "Apple, raw, with skin")
- Food database harmonization between USDA FoodData Central, FooDB, and custom datasets
- General text similarity on Apple Silicon Macs
Model Details
Files
gte-large.safetensors- Model weights in safetensors format (~670MB)config.json- Model architecture configurationtokenizer.json- Tokenizer vocabulary and settingstokenizer_config.json- Tokenizer configurationvocab.txt- WordPiece vocabularyspecial_tokens_map.json- Special token mappings
Usage with FoodMapper
FoodMapper offers this model as a one-time, user-started download during first-run setup.
Usage with MLX-Swift
import MLX
import MLXNN
// Load weights
let weights = try loadArrays(url: modelURL)
let parameters = ModuleParameters.unflattened(weights)
try model.update(parameters: parameters, verify: .none)Pooling
GTE models use mean pooling over token embeddings (not CLS token pooling). The attention mask should be applied before averaging:
func meanPooling(_ hiddenState: MLXArray, attentionMask: MLXArray) -> MLXArray {
let maskExpanded = attentionMask.expandedDimensions(axis: -1)
.asType(hiddenState.dtype)
let sumEmbeddings = (hiddenState * maskExpanded).sum(axis: 1)
let sumMask = MLX.maximum(maskExpanded.sum(axis: 1), MLXArray(1e-9))
return sumEmbeddings / sumMask
}Original Model
Based on thenlper/gte-large revision 4bef63f39fcc5e2d6b0aae83089f307af4970164 by Alibaba DAMO Academy.
License
MIT, as declared by the pinned original GTE-Large revision.
