Michael Marks commited on
Commit
dff620a
·
1 Parent(s): 3dd0806

add transformers notebook

Browse files
Files changed (1) hide show
  1. transformers.ipynb +71 -0
transformers.ipynb ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 6,
6
+ "metadata": {},
7
+ "outputs": [
8
+ {
9
+ "name": "stdout",
10
+ "output_type": "stream",
11
+ "text": [
12
+ "Token was found\n",
13
+ "<|im_start|>system\n",
14
+ "You are an AI assistant with access to various tools.<|im_end|>\n",
15
+ "<|im_start|>user\n",
16
+ "Hi !<|im_end|>\n",
17
+ "<|im_start|>assistant\n",
18
+ "Hi human, what can help you with ?<|im_end|>\n",
19
+ "<|im_start|>assistant\n",
20
+ "\n"
21
+ ]
22
+ }
23
+ ],
24
+ "source": [
25
+ "import os\n",
26
+ "\n",
27
+ "from transformers import AutoTokenizer\n",
28
+ "\n",
29
+ "messages = [\n",
30
+ " {\"role\": \"system\", \"content\": \"You are an AI assistant with access to various tools.\"},\n",
31
+ " {\"role\": \"user\", \"content\": \"Hi !\"},\n",
32
+ " {\"role\": \"assistant\", \"content\": \"Hi human, what can help you with ?\"},\n",
33
+ "]\n",
34
+ "\n",
35
+ "token = os.getenv('HF_TOKEN')\n",
36
+ "if token is None:\n",
37
+ " raise ValueError('You must set the HF_TOKEN environment variable')\n",
38
+ "else:\n",
39
+ " print('Token was found')\n",
40
+ " #print('Token:', token)\n",
41
+ "\n",
42
+ "\n",
43
+ "tokenizer = AutoTokenizer.from_pretrained(\"HuggingFaceTB/SmolLM2-1.7B-Instruct\", use_auth_token=token)\n",
44
+ "rendered_prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)\n",
45
+ "\n",
46
+ "print(rendered_prompt)"
47
+ ]
48
+ }
49
+ ],
50
+ "metadata": {
51
+ "kernelspec": {
52
+ "display_name": "Python 3",
53
+ "language": "python",
54
+ "name": "python3"
55
+ },
56
+ "language_info": {
57
+ "codemirror_mode": {
58
+ "name": "ipython",
59
+ "version": 3
60
+ },
61
+ "file_extension": ".py",
62
+ "mimetype": "text/x-python",
63
+ "name": "python",
64
+ "nbconvert_exporter": "python",
65
+ "pygments_lexer": "ipython3",
66
+ "version": "3.13.2"
67
+ }
68
+ },
69
+ "nbformat": 4,
70
+ "nbformat_minor": 2
71
+ }