Comments (5)
The issue you're encountering stems from using AutoTokenizer.from_pretrained
, which returns a tokenizer, not an embeddings model. Tokenizers prepare text for processing by models but don't generate embeddings themselves. To generate embeddings, you need to use a model designed for this purpose, such as those available from Hugging Face's transformers library.
For your specific need to use open-source models for embeddings, consider using models from the Hugging Face transformers library that are designed for generating embeddings. Here's a simplified approach:
-
Choose an Embeddings Model: Select a model from Hugging Face that is suitable for generating embeddings, such as
sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
. -
Load the Model and Tokenizer: Use the
AutoModel
andAutoTokenizer
classes to load your model and tokenizer.
from transformers import AutoModel, AutoTokenizer
model_name = "sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name)
- Generate Embeddings: After tokenizing your text, you can pass the tokenized input to your model to obtain embeddings.
inputs = tokenizer("Your text here", return_tensors="pt", padding=True, truncation=True)
with torch.no_grad():
outputs = model(**inputs)
embeddings = outputs.last_hidden_state.mean(dim=1) # Example of obtaining embeddings
This approach allows you to directly use models from Hugging Face for generating embeddings, bypassing the need for a method like get_text_embedding_batch
, which is not a standard method for Hugging Face models or tokenizers.
Remember, the key is to use a model that is capable of generating embeddings, as opposed to a tokenizer, which is only responsible for preparing text inputs for a model.
Details
Sources
- [Bug]: ctransformers not supported as OSS LLM models (from Huggingface)
- llama-index-core/llama_index/core/base/embeddings/base.py
- llama-index-integrations/embeddings/llama-index-embeddings-gradient/llama_index/embeddings/gradient/base.py
- llama-index-integrations/embeddings/llama-index-embeddings-adapter/llama_index/embeddings/adapter/base.py
- llama-index-integrations/embeddings/llama-index-embeddings-huggingface-optimum/llama_index/embeddings/huggingface_optimum/base.py
- llama-index-legacy/llama_index/legacy/embeddings/huggingface.py
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
To continue the conversation, mention @dosu.
from llama_index.
@logan-markewich I think you tagged me on accident
from llama_index.
Oops I did, whoops!
from llama_index.
@alineberry you set the embedding model to be a tokenizer. Probably you should do this
pip install llama-index-embeddings-huggingface
from llama_index.embeddings.huggingface import HuggingFaceEmbedding
embed_model = HuggingFaceEmbedding(model_name="<...>", embed_batch_size=10, device="<cpu or gpu>")
from llama_index.
😁 Man you really made my day 😂😂😂
from llama_index.
Related Issues (20)
- [Question]: Stream Responses of ReAct Agent Query Engine without intermediate steps HOT 4
- [Question]: How to handle multipe users, if they send messages to LLM concurrently. HOT 12
- [Bug]: readme link it's broken HOT 1
- [Question]: KeywordNodePostprocessor odd behavior? HOT 1
- Llama3-8B-Instruct not supported in `llama_index.llms.llama_cpp` HOT 7
- [Bug]: Running the IngestionPipleline twice is not working with SimpleVectorStore
- [Question]: Would you recommend appropriately format document (Text) for RAG ? HOT 1
- [Bug]: ModuleNotFoundError: No module named 'llama_index.readers.web.browserbase' HOT 5
- [Bug]: openai from_tools "tool with name functions not found" HOT 5
- [Feature Request]: Argilla Callback Handler updated, new README
- [Bug]: AzStorageBlobReader Nested Directories HOT 1
- [Bug]: llama-index-packs-resume-screener - AttributeError: 'BaseModel' object has no attribute HOT 2
- [Bug]: cannot import name 'BeautifulSoupWebReader' from 'llama_index.readers' (unknown location) HOT 2
- [Bug]: Not providing a model for the AzureOpenAI llm causes unexpected context size HOT 4
- [Question]: How can I use the SubQuestionQueryEngine to always decompose a user query to a ReActAgent? HOT 1
- [Question]: Combine/merge multiple VectorStoreIndex directories into a single index for querying HOT 1
- [Question]: cannot load config_sentence_transformers.json when using local BAAI/bge-small-en-v1.5 HOT 2
- Query a vector database against one question to return nodes, then query llm with another question against those nodes. HOT 7
- [Feature Request]: multiple value filter on same key in mongoDB vector store.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from llama_index.