gugarosa commited on
Commit
eac5218
1 Parent(s): e8a38cd

chore(readme): Updates with clear information.

Browse files
Files changed (1) hide show
  1. README.md +39 -38
README.md CHANGED
@@ -1,19 +1,22 @@
1
  ---
2
  inference: false
3
  license: other
 
 
4
  language:
5
- - en
 
6
  tags:
7
  - code
8
  ---
9
  ## Model Summary
10
 
11
- The language model phi-1 is a Transformer with 1.3 billion parameters, specialized for basic Python coding. Its training involved a variety of data sources, including subsets of Python codes from [The Stack v1.2](https://huggingface.co/datasets/bigcode/the-stack), Q&A content from [StackOverflow](https://archive.org/download/stackexchange), competition code from [code_contests](https://github.com/deepmind/code_contests), and synthetic Python textbooks and exercises generated by [gpt-3.5-turbo-0301](https://platform.openai.com/docs/models/gpt-3-5). Even though the model and the datasets are relatively small compared to contemporary Large Language Models (LLMs), phi-1 has demonstrated an impressive accuracy rate exceeding 50% on the simple Python coding benchmark, HumanEval.
12
 
13
  ## Intended Uses
14
- Given the nature of the training data, phi-1 is best suited for prompts using the code format:
15
 
16
- #### code format:
17
  ```python
18
  def print_prime(n):
19
  """
@@ -29,20 +32,45 @@ def print_prime(n):
29
  where the model generates the code after the comments. (Note: This is a legitimate and correct use of the else statement in Python loops.)
30
 
31
  **Notes**
32
- * phi-1 is intended for research purposes. The model-generated code should be treated as a starting point rather than a definitive solution for potential use cases. Users should be cautious when employing this model in their applications.
33
- * Direct adoption for production coding tasks is out of the scope of this research project. As a result, phi-1 has not been tested to ensure that it performs adequately for production-level code. Please refer to the limitation sections of this document for more details.
 
34
 
35
- ## Limitations of phi-1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
36
 
37
  * Limited Scope: 99.8% of the Python scripts in our fine-tuning dataset use only the packages "typing, math, random, collections, datetime, itertools". If the model generates Python scripts that utilize other packages, we strongly recommend users manually verify all API uses.
38
  * Replicate Scripts Online: As our model is trained on Python scripts found online, there is a small chance it may replicate such scripts, especially if they appear repetitively across different online sources.
39
  * Generate Inaccurate Code: The model frequently generates incorrect code. We suggest that users view these outputs as a source of inspiration rather than definitive solutions.
40
  * Unreliable Responses to Alternate Formats: Despite appearing to comprehend instructions in formats like Q&A or chat, our models often respond with inaccurate answers, even when seeming confident. Their capabilities with non-code formats are significantly more limited.
41
- * Limitations on Natural Language Comprehension. As a coding bot, phi-1's main focus is to help with coding-related questions. While it may have some natural language comprehension capabilities, its primary function is not to engage in general conversations or demonstrate common sense like a general AI assistant. Its strength lies in providing assistance and guidance in the context of programming and software development.
42
- * Potential Biases: phi-1, like other AI models, is trained on web and synthetic data. This data can contain biases and errors that might affect the AI's performance. Biases could stem from various sources like unbalanced representation, stereotypes, or controversial opinions present in the training data. As a result, the model might sometimes generate responses that reflect these biases or errors.
43
 
44
  ## Warning about Security Risks
45
- When leveraging phi-1, it's paramount to be vigilant. The model, though powerful, can inadvertently introduce security vulnerabilities in the generated code. Examples include, but are not limited to:
46
 
47
  * Directory Traversal: The code might fail to implement safe checks against directory traversal attacks, potentially allowing unauthorized access to sensitive files on your system.
48
  * Injection Attacks: There could be lapses in escaping strings properly, making the application susceptible to SQL, OS commands, or other injection attacks.
@@ -54,6 +82,7 @@ When leveraging phi-1, it's paramount to be vigilant. The model, though powerful
54
  Given these potential pitfalls, and others not explicitly mentioned, it's essential to thoroughly review, test, and verify the generated code before deploying it in any application, especially those that are security-sensitive. Always consult with security experts or perform rigorous penetration testing when in doubt.
55
 
56
  ## Training
 
57
  ### Model
58
  * Architecture: a Transformer-based model with next-word prediction objective
59
  * Training tokens: 54B tokens (7B unique tokens)
@@ -69,34 +98,6 @@ Given these potential pitfalls, and others not explicitly mentioned, it's essent
69
  ### License
70
  The model is licensed under the [Research License](https://huggingface.co/microsoft/phi-1/resolve/main/Research%20License.docx).
71
 
72
- ### Sample Code
73
- ```python
74
- import torch
75
- from transformers import AutoModelForCausalLM, AutoTokenizer
76
-
77
- torch.set_default_device("cuda")
78
- model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1", trust_remote_code=True)
79
- tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1", trust_remote_code=True)
80
- inputs = tokenizer('''def print_prime(n):
81
- """
82
- Print all primes between 1 and n
83
- """''', return_tensors="pt", return_attention_mask=False)
84
-
85
- outputs = model.generate(**inputs, max_length=200)
86
- text = tokenizer.batch_decode(outputs)[0]
87
- print(text)
88
- ```
89
-
90
- If you need to use the model in a lower precision (e.g., FP16), please wrap the model's forward pass with `torch.autocast()`, as follows:
91
- ```python
92
- with torch.autocast(model.device.type, dtype=torch.float16, enabled=True):
93
- outputs = model.generate(**inputs, max_length=200)
94
- ```
95
-
96
- **Remark.** In the generation function, our model currently does not support beam search (`num_beams` >1).
97
- Furthermore, in the forward pass of the model, we currently do not support outputting hidden states or attention values, or using custom input embeddings (instead of the model's).
98
-
99
-
100
  ### Citation
101
  ```bib
102
  @article{gunasekar2023textbooks,
 
1
  ---
2
  inference: false
3
  license: other
4
+ license_name: microsoft-research-license
5
+ license_link: https://huggingface.co/microsoft/phi-1/resolve/main/Research%20License.docx
6
  language:
7
+ - en
8
+ pipeline_tag: text-generation
9
  tags:
10
  - code
11
  ---
12
  ## Model Summary
13
 
14
+ The language model Phi-1 is a Transformer with 1.3 billion parameters, specialized for basic Python coding. Its training involved a variety of data sources, including subsets of Python codes from [The Stack v1.2](https://huggingface.co/datasets/bigcode/the-stack), Q&A content from [StackOverflow](https://archive.org/download/stackexchange), competition code from [code_contests](https://github.com/deepmind/code_contests), and synthetic Python textbooks and exercises generated by [gpt-3.5-turbo-0301](https://platform.openai.com/docs/models/gpt-3-5). Even though the model and the datasets are relatively small compared to contemporary Large Language Models (LLMs), phi-1 has demonstrated an impressive accuracy rate exceeding 50% on the simple Python coding benchmark, HumanEval.
15
 
16
  ## Intended Uses
17
+ Given the nature of the training data, Phi-1 is best suited for prompts using the code format:
18
 
19
+ ### Code Format:
20
  ```python
21
  def print_prime(n):
22
  """
 
32
  where the model generates the code after the comments. (Note: This is a legitimate and correct use of the else statement in Python loops.)
33
 
34
  **Notes**
35
+ * Phi-1 is intended for research purposes. The model-generated code should be treated as a starting point rather than a definitive solution for potential use cases. Users should be cautious when employing this model in their applications.
36
+ * Direct adoption for production coding tasks is out of the scope of this research project. As a result, Phi-1 has not been tested to ensure that it performs adequately for production-level code. Please refer to the limitation sections of this document for more details.
37
+ * If you are using `transformers>=4.36.0`, always load the model with `trust_remote_code=True` to prevent side-effects.
38
 
39
+ ## Sample Code
40
+ ```python
41
+ import torch
42
+ from transformers import AutoModelForCausalLM, AutoTokenizer
43
+
44
+ torch.set_default_device("cuda")
45
+
46
+ model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1", torch_dtype="auto", trust_remote_code=True)
47
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1", trust_remote_code=True)
48
+
49
+ inputs = tokenizer('''def print_prime(n):
50
+ """
51
+ Print all primes between 1 and n
52
+ """''', return_tensors="pt", return_attention_mask=False)
53
+
54
+ outputs = model.generate(**inputs, max_length=200)
55
+ text = tokenizer.batch_decode(outputs)[0]
56
+ print(text)
57
+ ```
58
+
59
+ **Remark.** In the generation function, our model currently does not support beam search (`num_beams` >1).
60
+ Furthermore, in the forward pass of the model, we currently do not support outputting hidden states or attention values, or using custom input embeddings.
61
+
62
+
63
+ ## Limitations of Phi-1
64
 
65
  * Limited Scope: 99.8% of the Python scripts in our fine-tuning dataset use only the packages "typing, math, random, collections, datetime, itertools". If the model generates Python scripts that utilize other packages, we strongly recommend users manually verify all API uses.
66
  * Replicate Scripts Online: As our model is trained on Python scripts found online, there is a small chance it may replicate such scripts, especially if they appear repetitively across different online sources.
67
  * Generate Inaccurate Code: The model frequently generates incorrect code. We suggest that users view these outputs as a source of inspiration rather than definitive solutions.
68
  * Unreliable Responses to Alternate Formats: Despite appearing to comprehend instructions in formats like Q&A or chat, our models often respond with inaccurate answers, even when seeming confident. Their capabilities with non-code formats are significantly more limited.
69
+ * Limitations on Natural Language Comprehension. As a coding bot, Phi-1's main focus is to help with coding-related questions. While it may have some natural language comprehension capabilities, its primary function is not to engage in general conversations or demonstrate common sense like a general AI assistant. Its strength lies in providing assistance and guidance in the context of programming and software development.
70
+ * Potential Biases: Phi-1, like other AI models, is trained on web and synthetic data. This data can contain biases and errors that might affect the AI's performance. Biases could stem from various sources like unbalanced representation, stereotypes, or controversial opinions present in the training data. As a result, the model might sometimes generate responses that reflect these biases or errors.
71
 
72
  ## Warning about Security Risks
73
+ When leveraging Phi-1, it's paramount to be vigilant. The model, though powerful, can inadvertently introduce security vulnerabilities in the generated code. Examples include, but are not limited to:
74
 
75
  * Directory Traversal: The code might fail to implement safe checks against directory traversal attacks, potentially allowing unauthorized access to sensitive files on your system.
76
  * Injection Attacks: There could be lapses in escaping strings properly, making the application susceptible to SQL, OS commands, or other injection attacks.
 
82
  Given these potential pitfalls, and others not explicitly mentioned, it's essential to thoroughly review, test, and verify the generated code before deploying it in any application, especially those that are security-sensitive. Always consult with security experts or perform rigorous penetration testing when in doubt.
83
 
84
  ## Training
85
+
86
  ### Model
87
  * Architecture: a Transformer-based model with next-word prediction objective
88
  * Training tokens: 54B tokens (7B unique tokens)
 
98
  ### License
99
  The model is licensed under the [Research License](https://huggingface.co/microsoft/phi-1/resolve/main/Research%20License.docx).
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  ### Citation
102
  ```bib
103
  @article{gunasekar2023textbooks,