Instructions to use eurecom-ds/Phi-3-mini-4k-socratic with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use eurecom-ds/Phi-3-mini-4k-socratic with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="eurecom-ds/Phi-3-mini-4k-socratic", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("eurecom-ds/Phi-3-mini-4k-socratic", trust_remote_code=True) model = AutoModelForCausalLM.from_pretrained("eurecom-ds/Phi-3-mini-4k-socratic", trust_remote_code=True) messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use eurecom-ds/Phi-3-mini-4k-socratic with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "eurecom-ds/Phi-3-mini-4k-socratic" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "eurecom-ds/Phi-3-mini-4k-socratic", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/eurecom-ds/Phi-3-mini-4k-socratic
- SGLang
How to use eurecom-ds/Phi-3-mini-4k-socratic 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 "eurecom-ds/Phi-3-mini-4k-socratic" \ --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": "eurecom-ds/Phi-3-mini-4k-socratic", "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 "eurecom-ds/Phi-3-mini-4k-socratic" \ --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": "eurecom-ds/Phi-3-mini-4k-socratic", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use eurecom-ds/Phi-3-mini-4k-socratic with Docker Model Runner:
docker model run hf.co/eurecom-ds/Phi-3-mini-4k-socratic
Socratic LLM
Using Large Language Models (LLMs) in education presents unique challenges. Typically, LLMs are designed to provide direct answers to questions, which can hinder students' critical thinking and self-discovery skills. To address this, we focus on fine-tuning LLMs to facilitate Socratic interactions. Instead of giving straightforward answers, these models guide students to explore and find the answers themselves. We achieve this through Direct Preference Optimization (DPO). We test our approach with diverse datasets, including various educational materials and Socratic dialogues. Using advanced models like GPT-4o for evaluation, our results show that DPO successfully fine-tunes LLMs for Socratic dialogue, enhancing their educational value.
Check out training pipeline at GitHub - socratic-llm.
And you can also run it with Ollama: eurecom-ds/phi-3-mini-4k-socratic!
Or, you can learn more about our project at Fine Tuning a Large Language Model for Socratic Interactions, and read our paper
Prompt Format
See Inference template.
Usage
from transformers import AutoTokenizer, AutoModelForCausalLM
import urllib.request
import torch
with urllib.request.urlopen("https://raw.githubusercontent.com/GiovanniGatti/socratic-llm/kdd-2024/templates/inference.txt") as f:
inference_prompt_template = f.read().decode('utf-8')
model = AutoModelForCausalLM.from_pretrained(
"eurecom-ds/Phi-3-mini-4k-socratic",
torch_dtype=torch.bfloat16,
trust_remote_code=True,
device_map="cuda",
)
tokenizer = AutoTokenizer.from_pretrained("eurecom-ds/Phi-3-mini-4k-socratic", trust_remote_code=True)
_input = "Student: Professor, why did Einstein say that God does not play dice?"
content = inference_prompt_template.format(input=_input)
formatted = tokenizer.apply_chat_template(
[{"role": "user", "content": content}, ], tokenize=False, add_generation_prompt=True
)
encoded_inputs = tokenizer([formatted, ], return_tensors="pt").to("cuda")
generate_kwargs = dict(encoded_inputs, max_new_tokens=250)
output = model.generate(**generate_kwargs)
response = tokenizer.decode(output[0], skip_prompt=True, skip_special_tokens=True)[len(content) + 1:]
print(response)
# That's a profound question! How do you think Einstein's perspective on determinism and quantum
# mechanics might influence his views on the nature of the universe?
- Downloads last month
- 50