Skip to content

Commit c9887c0

Browse files
Add Phi_4_Conversational notebook
1 parent d50891d commit c9887c0

File tree

1 file changed

+124
-0
lines changed

1 file changed

+124
-0
lines changed
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "7b502c12",
6+
"metadata": {
7+
"id": "7b502c12"
8+
},
9+
"source": [
10+
"# Phi-4 Conversational Chat"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "6f550ca9",
16+
"metadata": {
17+
"id": "6f550ca9"
18+
},
19+
"source": [
20+
"**Description:**\n",
21+
"\n",
22+
"Basic conversational inference with Phi-4 demonstrating chat-style turn-based communication."
23+
]
24+
},
25+
{
26+
"cell_type": "markdown",
27+
"source": [
28+
"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/Phi_4_Conversational.ipynb)\n"
29+
],
30+
"metadata": {
31+
"id": "CB4mkM7yPmua"
32+
},
33+
"id": "CB4mkM7yPmua"
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"id": "e0db4638",
38+
"metadata": {
39+
"id": "e0db4638"
40+
},
41+
"source": [
42+
"**Dependencies**\n",
43+
"\n",
44+
"```python\n",
45+
"!pip install transformers accelerate\n",
46+
"!pip install torch\n",
47+
"```"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"id": "25ef05dd",
53+
"metadata": {
54+
"id": "25ef05dd"
55+
},
56+
"source": [
57+
"**Tools Used**\n",
58+
"\n",
59+
"- HuggingFace Transformers\n",
60+
"- PyTorch"
61+
]
62+
},
63+
{
64+
"cell_type": "markdown",
65+
"id": "8986b9d8",
66+
"metadata": {
67+
"id": "8986b9d8"
68+
},
69+
"source": [
70+
"**YAML Prompt**\n",
71+
"\n",
72+
"```yaml\n",
73+
"system: You are a tutor.\n",
74+
"user: Teach me what machine learning is.\n",
75+
"```"
76+
]
77+
},
78+
{
79+
"cell_type": "code",
80+
"execution_count": null,
81+
"id": "ffdb2319",
82+
"metadata": {
83+
"id": "ffdb2319"
84+
},
85+
"outputs": [],
86+
"source": [
87+
"from transformers import AutoTokenizer, AutoModelForCausalLM\n",
88+
"\n",
89+
"tokenizer = AutoTokenizer.from_pretrained(\"microsoft/phi-4\")\n",
90+
"model = AutoModelForCausalLM.from_pretrained(\"microsoft/phi-4\")\n",
91+
"\n",
92+
"prompt = \"Teach me what machine learning is.\"\n",
93+
"inputs = tokenizer(prompt, return_tensors=\"pt\")\n",
94+
"outputs = model.generate(**inputs, max_new_tokens=80)\n",
95+
"print(tokenizer.decode(outputs[0], skip_special_tokens=True))"
96+
]
97+
},
98+
{
99+
"cell_type": "markdown",
100+
"id": "ac4caeac",
101+
"metadata": {
102+
"id": "ac4caeac"
103+
},
104+
"source": [
105+
"**Output**\n",
106+
"\n",
107+
"Explains machine learning in a clear, tutor-like manner.\n",
108+
"\n",
109+
"Machine learning is a field of artificial intelligence that allows computers to learn from data without being explicitly programmed.\n",
110+
"It involves training algorithms on large datasets so they can recognize patterns, make decisions, or perform tasks.\n",
111+
"There are different types of machine learning, including supervised, unsupervised, and reinforcement learning.\n",
112+
"For example, in supervised learning, a model is trained using labeled data to predict outcomes.\n",
113+
"Overall, machine learning is widely used in applications like recommendation systems, image recognition, and natural language processing.\n"
114+
]
115+
}
116+
],
117+
"metadata": {
118+
"colab": {
119+
"provenance": []
120+
}
121+
},
122+
"nbformat": 4,
123+
"nbformat_minor": 5
124+
}

0 commit comments

Comments
 (0)