Instructions to use FinaPolat/phi4_adaptableIE_v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use FinaPolat/phi4_adaptableIE_v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="FinaPolat/phi4_adaptableIE_v2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("FinaPolat/phi4_adaptableIE_v2") model = AutoModelForCausalLM.from_pretrained("FinaPolat/phi4_adaptableIE_v2") 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]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use FinaPolat/phi4_adaptableIE_v2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "FinaPolat/phi4_adaptableIE_v2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "FinaPolat/phi4_adaptableIE_v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/FinaPolat/phi4_adaptableIE_v2
- SGLang
How to use FinaPolat/phi4_adaptableIE_v2 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 "FinaPolat/phi4_adaptableIE_v2" \ --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": "FinaPolat/phi4_adaptableIE_v2", "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 "FinaPolat/phi4_adaptableIE_v2" \ --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": "FinaPolat/phi4_adaptableIE_v2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Unsloth Studio new
How to use FinaPolat/phi4_adaptableIE_v2 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 FinaPolat/phi4_adaptableIE_v2 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 FinaPolat/phi4_adaptableIE_v2 to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for FinaPolat/phi4_adaptableIE_v2 to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="FinaPolat/phi4_adaptableIE_v2", max_seq_length=2048, ) - Docker Model Runner
How to use FinaPolat/phi4_adaptableIE_v2 with Docker Model Runner:
docker model run hf.co/FinaPolat/phi4_adaptableIE_v2
# Load model directly
from transformers import AutoTokenizer, AutoModelForCausalLM
tokenizer = AutoTokenizer.from_pretrained("FinaPolat/phi4_adaptableIE_v2")
model = AutoModelForCausalLM.from_pretrained("FinaPolat/phi4_adaptableIE_v2")
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]:]))Phi-4-AdaptableIE: Efficient Adaptive Knowledge Graph Extraction
This model has gguf version: https://huggingface.co/FinaPolat/phi4_adaptableIE_v2-gguf
Phi-4-AdaptableIE is a specialized 14.7B parameter Small Language Model (SLM) optimized via Supervised Fine-Tuning (SFT) for high-precision, Joint Named Entity Recognition (NER) and Relation Extraction (RE).
Unlike traditional multi-stage pipelines that are prone to cascading error propagation, this model performs entity identification and relational mapping in a single cohesive pass. It is designed to be ontology-adaptive, allowing it to conform to dynamic, unseen schemas at inference time through a specialized Structured Prompt Architecture.
🚀 Model Highlights
- Joint Extraction: Unified NER + RE reducing pipeline complexity.
- Ontology-Adaptive: Zero-shot adaptation to diverse domains (Astronomy, Music, Healthcare, etc.) via dynamic schema variables.
- Local & Private: Optimized for local CPU-only inference (via GGUF/Ollama - FinaPolat/phi4_adaptableIE_v2-gguf ), ensuring data sovereignty without external API dependencies.
- Instruction Aligned: Fine-tuned to follow strict negative constraints, ensuring zero conversational filler in outputs.
🛠 Methodology
The model was fine-tuned using QLoRA on the WebNLG subset of the Text2KGBench benchmark. The training process focused on Conversational Alignment, ensuring the model treats extraction as a strict logical mapping:
Prompt = f(task, schema, example, text)
📝 Prompting Strategy
To achieve high-fidelity extraction, the model requires a specific prompt structure.
1. System Prompt
{
"role": "system",
"content": "You are a helpful AI assistant specializing in Information Extraction tasks such as Named Entity Recognition and Relation Extraction. Follow the instructions given by the user."
}
2. User Prompt Template
Information Extraction is the process of automatically identifying and extracting structured information from unstructured text data... [Context] ...
Always extract numbers, dates, and currency values regardless of the specific task.
The task at hand is {task}.
Here is an example of task execution:
{example}
Analyze the text and targets carefully, identify relevant information.
Extract the information in the following format: `{output_format}`.
If no matching entities are found, return an empty list: [].
Please provide only the extracted information without any explanations.
Schema: {schema}
Text: {inputs}
3. 💻 Usage Examples
Option 1: Transformers (Single GPU)
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "FinaPolat/phi4_adaptableIE_v2"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", trust_remote_code=True)
task = "Joint NER and RE"
schema = "['CelestialBody', 'apoapsis', 'averageSpeed']"
inputs = "(19255) 1994 VK8 has an average speed of 4.56 km per second."
output_format = "[('subject', 'predicate', 'object')]"
prompt = f"Task: {task}\nSchema: {schema}\nText: {inputs}\nExtract:"
input_ids = tokenizer(prompt, return_tensors="pt").to("cuda")
outputs = model.generate(**input_ids, max_new_tokens=256, temperature=0.0)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
Option 2: High-Throughput Batch Inference (vLLM)
from vllm import LLM, SamplingParams
llm = LLM(
model="FinaPolat/phi4_adaptableIE_v2",
dtype="bfloat16",
trust_remote_code=True,
gpu_memory_utilization=0.9,
max_model_len=3000,
enforce_eager=True,
distributed_executor_backend="uni"
)
sampling_params = SamplingParams(temperature=0.0, max_tokens=256)
outputs = llm.chat(batch_prompts, sampling_params=sampling_params, use_tqdm=True)
4. 📦 Deployment & Hardware Requirements
| Deployment Mode | Quantization | Hardware Requirement | Target Latency |
|---|---|---|---|
| Server-side | BF16 | 1× NVIDIA A100 / RTX 4090 (24GB+) | Ultra-Low |
| Local Consumer | 4-bit GGUF | 16GB RAM (Apple Silicon / PC CPU) | Moderate |
For CPU-only local execution, refer to the GGUF version: phi4_adaptableIE_v2-gguf📜
5. Citation & Credits
If you use this model in your research, please cite the Text2KGBench framework and the Microsoft Phi-4 technical report and our work: https://github.com/FinaPolat/ENEXA_adaptable_extraction
- Downloads last month
- 3
Model tree for FinaPolat/phi4_adaptableIE_v2
Base model
microsoft/phi-4
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="FinaPolat/phi4_adaptableIE_v2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)