Phi-2: a 2.7B language model by Microsoft Research that demonstrates outstanding reasoning and language understanding capabilities.

2.7b

397.2K 10 months ago

Readme

Phi-2 is a small language model capable of common-sense reasoning and language understanding. It showcases “state-of-the-art performance” among language models with less than 13 billion parameters.

Example prompt

By default, phi includes a chat prompt template designed for multi-turn conversations:

% ollama run phi
>>> Hello, can you help me find my way to Toronto?
 Certainly! What is the exact location in Toronto that you are looking for?

>>> Yonge & Bloor
 Sure, Yonge and Bloor is a busy intersection in downtown Toronto. Would you like to take public transportation or drive there?

>>> Public transportation
 Great! The easiest way to get there is by taking the TTC subway. You can take Line 1, which runs along Yonge Street and passes through downtown Toronto.

Using Ollama’s API:

curl http://localhost:11434/api/chat -d '{
  "model": "phi",
  "messages": [
    { "role": "user", "content": "why is the sky blue?" }
  ]
}'

Example prompts (raw mode)

Phi also responds well to a wide variety of prompt formats when using raw mode in Ollama’s API, which bypasses all default prompt templating:

Instruct

curl http://localhost:11434/api/generate -d '{
  "model": "phi",
  "prompt": "Instruct: Write a detailed analogy between mathematics and a lighthouse.\nOutput:",
  "options": {
    "stop": ["Instruct:", "Output:"]
  },
  "raw": true,
  "stream": false
}'

Code Completion

curl http://localhost:11434/api/generate -d '{
  "model": "phi",
  "prompt": "def print_prime(n):\n  ",
  "raw": true,
  "stream": false
}'

Text completion

curl http://localhost:11434/api/generate -d '{
  "model": "phi",
  "prompt": "There once was a mouse named",
  "raw": true,
  "stream": false
}'

References

HuggingFace

Blog Post