Instructions to use DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1", dtype="auto") - llama-cpp-python
How to use DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1", filename="text2cypher-gemma-2-9b-it-finetuned-2024v1-Q4_0.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0 # Run inference directly in the terminal: llama-cli -hf DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0 # Run inference directly in the terminal: llama-cli -hf DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0 # Run inference directly in the terminal: ./llama-cli -hf DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0 # Run inference directly in the terminal: ./build/bin/llama-cli -hf DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0
Use Docker
docker model run hf.co/DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0
- LM Studio
- Jan
- vLLM
How to use DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0
- SGLang
How to use DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 with Ollama:
ollama run hf.co/DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0
- Unsloth Studio
How to use DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 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 DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 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 DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 to start chatting
- Atomic Chat new
- Docker Model Runner
How to use DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 with Docker Model Runner:
docker model run hf.co/DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0
- Lemonade
How to use DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1 with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1:Q4_0
Run and chat with the model
lemonade run user.text2cypher-gemma-2-9b-it-finetuned-2024v1-Q4_0
List all available models
lemonade list
YAML Metadata Warning:The pipeline tag "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other
Model Card for Model ID
Model Details
Model Description
This model serves as a demonstration of how fine-tuning foundational models using the Neo4j-Text2Cypher(2024) Dataset (link) can enhance performance on the Text2Cypher task.
Please note, this is part of ongoing research and exploration, aimed at highlighting the dataset's potential rather than a production-ready solution.
Base model: google/gemma-2-9b-it
Dataset: neo4j/text2cypher-2024v1
An overview of the finetuned models and benchmarking results are shared at Link1 and Link2
Have ideas or insights? Contact us: Neo4j/Team-GenAI
Bias, Risks, and Limitations
We need to be cautious about a few risks:
- In our evaluation setup, the training and test sets come from the same data distribution (sampled from a larger dataset). If the data distribution changes, the results may not follow the same pattern.
- The datasets used were gathered from publicly available sources. Over time, foundational models may access both the training and test sets, potentially achieving similar or even better results.
Also check the related blogpost:Link
Training Details
Training Procedure
Used RunPod with following setup:
- 1 x A100 PCIe
- 31 vCPU 117 GB RAM
- runpod/pytorch:2.4.0-py3.11-cuda12.4.1-devel-ubuntu22.04
- On-Demand - Secure Cloud
- 60 GB Disk
- 60 GB Pod Volume
Training Hyperparameters
- lora_config = LoraConfig( r=64, lora_alpha=64, target_modules=target_modules, lora_dropout=0.05, bias="none", task_type="CAUSAL_LM", )
- sft_config = SFTConfig( dataset_text_field=dataset_text_field, per_device_train_batch_size=4, gradient_accumulation_steps=8, dataset_num_proc=16, max_seq_length=1600, logging_dir="./logs", num_train_epochs=1, learning_rate=2e-5, save_steps=5, save_total_limit=1, logging_steps=5, output_dir="outputs", optim="paged_adamw_8bit", save_strategy="steps", )
- bnb_config = BitsAndBytesConfig( load_in_4bit=True, bnb_4bit_use_double_quant=True, bnb_4bit_quant_type="nf4", bnb_4bit_compute_dtype=torch.bfloat16, )
Framework versions
- PEFT 0.12.0
Example Cypher generation
from transformers import AutoModelForCausalLM, AutoTokenizer import torch model_name = "DavidLanz/text2cypher-gemma-2-9b-it-finetuned-2024v1" model = AutoModelForCausalLM.from_pretrained( model_name, torch_dtype=torch.float32, device_map="auto", low_cpu_mem_usage=True, ) tokenizer = AutoTokenizer.from_pretrained(model_name) question = "What are the movies of Tom Hanks?" schema = "(:Actor)-[:ActedIn]->(:Movie)" instruction = ( "Generate Cypher statement to query a graph database. " "Use only the provided relationship types and properties in the schema. \n" "Schema: {schema} \n Question: {question} \n Cypher output: " ) prompt = instruction.format(schema=schema, question=question) inputs = tokenizer(prompt, return_tensors="pt").to("cuda") model.eval() with torch.no_grad(): outputs = model.generate(**inputs, max_new_tokens=512) generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) print("Generated Cypher Query:", generated_text) def prepare_chat_prompt(question, schema): chat = [ { "role": "user", "content": instruction.format( schema=schema, question=question ), } ] return chat def _postprocess_output_cypher(output_cypher: str) -> str: # Remove any explanation or formatting markers partition_by = "**Explanation:**" output_cypher, _, _ = output_cypher.partition(partition_by) output_cypher = output_cypher.strip("`\n") output_cypher = output_cypher.lstrip("cypher\n") output_cypher = output_cypher.strip("`\n ") return output_cypher new_message = prepare_chat_prompt(question=question, schema=schema) try: prompt = tokenizer.apply_chat_template(new_message, add_generation_prompt=True, tokenize=False) inputs = tokenizer(prompt, return_tensors="pt", padding=True).to("cuda") with torch.no_grad(): outputs = model.generate(**inputs, max_new_tokens=512) chat_generated_text = tokenizer.decode(outputs[0], skip_special_tokens=True) final_cypher = _postprocess_output_cypher(chat_generated_text) print("Processed Cypher Query:", final_cypher) except AttributeError: print("Error: `apply_chat_template` not supported by this tokenizer. Check compatibility.")
- Downloads last month
- -
4-bit
5-bit