Instructions to use prdev/query-gen with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use prdev/query-gen with Transformers:
# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("prdev/query-gen", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- Unsloth Studio
How to use prdev/query-gen with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for prdev/query-gen to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for prdev/query-gen to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for prdev/query-gen to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="prdev/query-gen", max_seq_length=2048, )
| base_model: unsloth/llama-3.2-1b-instruct-unsloth-bnb-4bit | |
| tags: | |
| - text-generation-inference | |
| - transformers | |
| - unsloth | |
| - llama | |
| - trl | |
| license: apache-2.0 | |
| language: | |
| - en | |
| # Query Generation with LoRA Finetuning | |
| This project fine-tunes a language model using supervised fine-tuning (SFT) and LoRA adapters to generate queries from documents. The model was trained on the [`prdev/qtack-gq-embeddings-unsupervised`](https://huggingface.co/datasets/prdev/qtack-gq-embeddings-unsupervised) dataset using an A100 GPU. | |
| ## Overview | |
| - **Objective:** | |
| The goal is to train a model that, given a document, generates a relevant query. Each training example is formatted with custom markers: | |
| - `<|document|>\n` precedes the document text. | |
| - `<|query|>\n` precedes the query text. | |
| - An EOS token is appended at the end to signal termination. | |
| - **Text Chunking:** | |
| For optimal performance, **chunk your text** into smaller, coherent pieces before providing it to the model. Long documents can lead the model to focus on specific details rather than the overall context. | |
| - **Training Setup:** | |
| The model is fine-tuned using the Unsloth framework with LoRA adapters, taking advantage of an A100 GPU for efficient training. See W&B loss curve here: https://wandb.ai/prdev/lora_model_training/panel/jp2r24xk7?nw=nwuserprdev | |
| ## Quick Usage | |
| Below is an example code snippet to load the finetuned model and test it with a chunked document: | |
| ```python | |
| from unsloth import FastLanguageModel | |
| from transformers import TextStreamer | |
| # Load the finetuned model and tokenizer from Hugging Face Hub. | |
| model, tokenizer = FastLanguageModel.from_pretrained("prdev/query-gen", load_in_4bit=True) | |
| # Enable faster inference if supported. | |
| FastLanguageModel.for_inference(model) | |
| # Example document chunk (ensure text is appropriately chunked). | |
| document_chunk = ( | |
| "liberal arts. 1. the academic course of instruction at a college intended to provide general knowledge " | |
| "and comprising the arts, humanities, natural sciences, and social sciences, as opposed to professional or technical subjects." | |
| ) | |
| # Create the prompt using custom markers. | |
| prompt = ( | |
| "<|document|>\n" + document_chunk + "\n<|query|>\n" | |
| ) | |
| # Tokenize the prompt. | |
| inputs = tokenizer(prompt, return_tensors="pt").to("cuda") | |
| # Set up a TextStreamer to view token-by-token generation. | |
| streamer = TextStreamer(tokenizer, skip_prompt=True) | |
| # Generate a query from the document. | |
| _ = model.generate( | |
| input_ids=inputs["input_ids"], | |
| streamer=streamer, | |
| max_new_tokens=100, | |
| temperature=0.7, | |
| min_p=0.1, | |
| eos_token_id=tokenizer.eos_token_id, # Ensures proper termination. | |
| ) | |
| ``` | |
| # Uploaded model | |
| - **Developed by:** prdev | |
| - **License:** apache-2.0 | |
| - **Finetuned from model :** unsloth/llama-3.2-1b-instruct-unsloth-bnb-4bit | |
| This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library. | |
| [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth) | |