Skip to content

Conversation

@xenova
Copy link
Collaborator

@xenova xenova commented Feb 15, 2024

Needed for nomic-ai/nomic-embed-text-v1.5.

Example usage:

import { pipeline, layer_norm } from '@xenova/transformers';

// Create a feature extraction pipeline
const extractor = await pipeline('feature-extraction', 'nomic-ai/nomic-embed-text-v1.5', {
    quantized: false, // Comment out this line to use the quantized version
});

// Compute sentence embeddings
const texts = ['search_query: What is TSNE?', 'search_query: Who is Laurens van der Maaten?'];
let embeddings = await extractor(texts, { pooling: 'mean' });

const matryoshka_dim = 512;
embeddings = layer_norm(embeddings, [embeddings.dims[1]])
    .slice(null, [0, matryoshka_dim])
    .normalize(2, -1);
console.log(embeddings.tolist());
// [
//   [-0.00518727907910943,   0.06514579057693481,  -0.21559129655361176, ...],
//   [-0.008253306150436401,  0.005108598619699478,   -0.22179779410362244, ...],
// ]

Relevant discussion: https://huggingface.co/nomic-ai/nomic-embed-text-v1.5/discussions/4#65cce8d0c52afc14ceac26c2

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@xenova xenova merged commit e9092d2 into main Feb 19, 2024
@xenova xenova deleted the add-layer-norm branch February 19, 2024 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants