Instructions to use farid678/code-search-net-tokenizer with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use farid678/code-search-net-tokenizer with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("farid678/code-search-net-tokenizer", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -1,13 +1,21 @@
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
-
tags:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
---
|
| 5 |
|
| 6 |
-
# Model Card for
|
| 7 |
|
| 8 |
<!-- Provide a quick summary of what the model is/does. -->
|
| 9 |
|
| 10 |
-
|
| 11 |
|
| 12 |
## Model Details
|
| 13 |
|
|
@@ -15,21 +23,23 @@ tags: []
|
|
| 15 |
|
| 16 |
<!-- Provide a longer summary of what this model is. -->
|
| 17 |
|
| 18 |
-
This
|
|
|
|
|
|
|
| 19 |
|
| 20 |
-
- **Developed by:** [
|
| 21 |
- **Funded by [optional]:** [More Information Needed]
|
| 22 |
-
- **Shared by [optional]:**
|
| 23 |
-
- **Model type:**
|
| 24 |
-
- **Language(s) (NLP):**
|
| 25 |
- **License:** [More Information Needed]
|
| 26 |
-
- **Finetuned from model
|
| 27 |
|
| 28 |
### Model Sources [optional]
|
| 29 |
|
| 30 |
<!-- Provide the basic links for the model. -->
|
| 31 |
|
| 32 |
-
- **Repository:**
|
| 33 |
- **Paper [optional]:** [More Information Needed]
|
| 34 |
- **Demo [optional]:** [More Information Needed]
|
| 35 |
|
|
@@ -41,37 +51,54 @@ This is the model card of a 🤗 transformers model that has been pushed on the
|
|
| 41 |
|
| 42 |
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
### Downstream Use [optional]
|
| 47 |
|
| 48 |
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 49 |
|
| 50 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 51 |
|
| 52 |
### Out-of-Scope Use
|
| 53 |
|
| 54 |
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 55 |
|
| 56 |
-
|
| 57 |
|
| 58 |
## Bias, Risks, and Limitations
|
| 59 |
|
| 60 |
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 61 |
|
| 62 |
-
|
|
|
|
|
|
|
| 63 |
|
| 64 |
### Recommendations
|
| 65 |
|
| 66 |
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 67 |
|
| 68 |
-
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the
|
| 69 |
|
| 70 |
## How to Get Started with the Model
|
| 71 |
|
| 72 |
-
Use the code below to get started with the
|
| 73 |
|
| 74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 75 |
|
| 76 |
## Training Details
|
| 77 |
|
|
@@ -79,20 +106,31 @@ Use the code below to get started with the model.
|
|
| 79 |
|
| 80 |
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 81 |
|
| 82 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
|
| 84 |
### Training Procedure
|
| 85 |
|
| 86 |
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 87 |
|
| 88 |
-
|
| 89 |
|
| 90 |
-
|
| 91 |
|
|
|
|
| 92 |
|
| 93 |
#### Training Hyperparameters
|
| 94 |
|
| 95 |
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
|
|
|
|
|
|
| 96 |
|
| 97 |
#### Speeds, Sizes, Times [optional]
|
| 98 |
|
|
@@ -122,7 +160,7 @@ Use the code below to get started with the model.
|
|
| 122 |
|
| 123 |
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 124 |
|
| 125 |
-
[More Information Needed]
|
| 126 |
|
| 127 |
### Results
|
| 128 |
|
|
@@ -130,7 +168,7 @@ Use the code below to get started with the model.
|
|
| 130 |
|
| 131 |
#### Summary
|
| 132 |
|
| 133 |
-
|
| 134 |
|
| 135 |
## Model Examination [optional]
|
| 136 |
|
|
@@ -154,7 +192,7 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
|
|
| 154 |
|
| 155 |
### Model Architecture and Objective
|
| 156 |
|
| 157 |
-
|
| 158 |
|
| 159 |
### Compute Infrastructure
|
| 160 |
|
|
@@ -166,7 +204,9 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
|
|
| 166 |
|
| 167 |
#### Software
|
| 168 |
|
| 169 |
-
|
|
|
|
|
|
|
| 170 |
|
| 171 |
## Citation [optional]
|
| 172 |
|
|
@@ -174,17 +214,26 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
|
|
| 174 |
|
| 175 |
**BibTeX:**
|
| 176 |
|
| 177 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
**APA:**
|
| 180 |
|
| 181 |
-
|
| 182 |
|
| 183 |
## Glossary [optional]
|
| 184 |
|
| 185 |
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 186 |
|
| 187 |
-
|
|
|
|
| 188 |
|
| 189 |
## More Information [optional]
|
| 190 |
|
|
@@ -192,8 +241,8 @@ Carbon emissions can be estimated using the [Machine Learning Impact calculator]
|
|
| 192 |
|
| 193 |
## Model Card Authors [optional]
|
| 194 |
|
| 195 |
-
|
| 196 |
|
| 197 |
## Model Card Contact
|
| 198 |
|
| 199 |
-
|
|
|
|
| 1 |
---
|
| 2 |
library_name: transformers
|
| 3 |
+
tags:
|
| 4 |
+
- gpt2
|
| 5 |
+
- tokenizer
|
| 6 |
+
- code
|
| 7 |
+
- python
|
| 8 |
+
- code-search-net
|
| 9 |
+
datasets:
|
| 10 |
+
- code_search_net
|
| 11 |
+
base_model: gpt2
|
| 12 |
---
|
| 13 |
|
| 14 |
+
# Model Card for farid678/gpt2-python-tokenizer
|
| 15 |
|
| 16 |
<!-- Provide a quick summary of what the model is/does. -->
|
| 17 |
|
| 18 |
+
A new byte-level BPE tokenizer trained from scratch for GPT-2, specialized for Python source code, using the `code_search_net` (Python subset) dataset.
|
| 19 |
|
| 20 |
## Model Details
|
| 21 |
|
|
|
|
| 23 |
|
| 24 |
<!-- Provide a longer summary of what this model is. -->
|
| 25 |
|
| 26 |
+
This repository contains a custom tokenizer trained from the base GPT-2 tokenizer architecture, re-trained on the Python portion of the `code_search_net` dataset. The goal of this tokenizer is to better capture Python-specific syntax, keywords, identifiers, and code patterns (e.g. indentation, operators, common function/variable naming conventions) compared to the original GPT-2 tokenizer, which was trained primarily on natural language web text.
|
| 27 |
+
|
| 28 |
+
This tokenizer can be paired with a GPT-2 model (either the original pretrained weights with an extended/adapted embedding layer, or a model trained from scratch) for downstream tasks involving Python code, such as code completion, code summarization, or code generation.
|
| 29 |
|
| 30 |
+
- **Developed by:** [farid678](https://huggingface.co/farid678)
|
| 31 |
- **Funded by [optional]:** [More Information Needed]
|
| 32 |
+
- **Shared by [optional]:** farid678
|
| 33 |
+
- **Model type:** Byte-level BPE tokenizer (GPT-2 architecture)
|
| 34 |
+
- **Language(s) (NLP):** Python (programming language); tokenizer vocabulary derived from source code rather than natural language
|
| 35 |
- **License:** [More Information Needed]
|
| 36 |
+
- **Finetuned from model:** `gpt2` (tokenizer re-trained from scratch on new data, using GPT-2's tokenizer architecture as the base)
|
| 37 |
|
| 38 |
### Model Sources [optional]
|
| 39 |
|
| 40 |
<!-- Provide the basic links for the model. -->
|
| 41 |
|
| 42 |
+
- **Repository:** https://huggingface.co/farid678
|
| 43 |
- **Paper [optional]:** [More Information Needed]
|
| 44 |
- **Demo [optional]:** [More Information Needed]
|
| 45 |
|
|
|
|
| 51 |
|
| 52 |
<!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
|
| 53 |
|
| 54 |
+
This tokenizer can be used directly to tokenize Python source code for input into a GPT-2-style language model. It is intended for use in code-related NLP pipelines such as tokenizing datasets before training/fine-tuning a language model on Python code.
|
| 55 |
|
| 56 |
### Downstream Use [optional]
|
| 57 |
|
| 58 |
<!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
|
| 59 |
|
| 60 |
+
Intended to be paired with a GPT-2 (or GPT-2-style) causal language model for tasks such as:
|
| 61 |
+
- Python code completion
|
| 62 |
+
- Python code generation
|
| 63 |
+
- Code summarization / docstring generation
|
| 64 |
+
- Code-to-text or text-to-code tasks
|
| 65 |
|
| 66 |
### Out-of-Scope Use
|
| 67 |
|
| 68 |
<!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
|
| 69 |
|
| 70 |
+
This tokenizer is optimized for Python code and is not expected to perform well on natural language text or other programming languages (e.g. Java, C++, JavaScript) since its vocabulary was derived specifically from Python source code in `code_search_net`. It should not be used as a general-purpose natural language tokenizer.
|
| 71 |
|
| 72 |
## Bias, Risks, and Limitations
|
| 73 |
|
| 74 |
<!-- This section is meant to convey both technical and sociotechnical limitations. -->
|
| 75 |
|
| 76 |
+
- The tokenizer's vocabulary reflects patterns present in the `code_search_net` Python subset, which is sourced from public open-source GitHub repositories. As such, it may inherit biases present in that codebase (e.g. naming conventions, coding styles, or underrepresentation of certain coding domains).
|
| 77 |
+
- Performance on code written in significantly different styles, older Python versions, or non-English identifiers/comments may be degraded.
|
| 78 |
+
- This tokenizer alone does not generate code; it must be paired with a trained language model to be useful for downstream tasks.
|
| 79 |
|
| 80 |
### Recommendations
|
| 81 |
|
| 82 |
<!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
|
| 83 |
|
| 84 |
+
Users (both direct and downstream) should be made aware of the risks, biases and limitations of the tokenizer. It is recommended to evaluate tokenization quality (e.g. compression rate, out-of-vocabulary handling) on your own target dataset before relying on it for production use.
|
| 85 |
|
| 86 |
## How to Get Started with the Model
|
| 87 |
|
| 88 |
+
Use the code below to get started with the tokenizer.
|
| 89 |
|
| 90 |
+
```python
|
| 91 |
+
from transformers import AutoTokenizer
|
| 92 |
+
|
| 93 |
+
tokenizer = AutoTokenizer.from_pretrained("farid678/gpt2-python-tokenizer")
|
| 94 |
+
|
| 95 |
+
code_sample = "def hello_world():\n print('Hello, world!')"
|
| 96 |
+
tokens = tokenizer.tokenize(code_sample)
|
| 97 |
+
print(tokens)
|
| 98 |
+
|
| 99 |
+
encoded = tokenizer(code_sample)
|
| 100 |
+
print(encoded["input_ids"])
|
| 101 |
+
```
|
| 102 |
|
| 103 |
## Training Details
|
| 104 |
|
|
|
|
| 106 |
|
| 107 |
<!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
|
| 108 |
|
| 109 |
+
The tokenizer was trained on the **Python subset** of the [`code_search_net`](https://huggingface.co/datasets/code_search_net) dataset:
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
from datasets import load_dataset
|
| 113 |
+
|
| 114 |
+
raw_dataset = load_dataset("code_search_net", "python")
|
| 115 |
+
```
|
| 116 |
+
|
| 117 |
+
`code_search_net` contains functions and methods collected from open-source GitHub repositories, along with their associated docstrings/comments. The Python configuration used here consists of Python source code specifically.
|
| 118 |
|
| 119 |
### Training Procedure
|
| 120 |
|
| 121 |
<!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
|
| 122 |
|
| 123 |
+
A new byte-level BPE tokenizer was trained from scratch using the GPT-2 tokenizer architecture as a template (i.e. `tokenizer.train_new_from_iterator` from the 🤗 Tokenizers/Transformers library), using the raw code text from `code_search_net` (Python) as the training corpus.
|
| 124 |
|
| 125 |
+
#### Preprocessing [optional]
|
| 126 |
|
| 127 |
+
Python code and associated documentation strings from `code_search_net` were used as raw text input for tokenizer training. [More Information Needed] (exact preprocessing steps, e.g. whether docstrings/comments were included or code-only)
|
| 128 |
|
| 129 |
#### Training Hyperparameters
|
| 130 |
|
| 131 |
- **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
|
| 132 |
+
- **Vocabulary size:** [More Information Needed]
|
| 133 |
+
- **Base tokenizer:** `gpt2` (byte-level BPE)
|
| 134 |
|
| 135 |
#### Speeds, Sizes, Times [optional]
|
| 136 |
|
|
|
|
| 160 |
|
| 161 |
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
| 162 |
|
| 163 |
+
[More Information Needed] (e.g. average tokens per line of code, compression ratio vs. original GPT-2 tokenizer, out-of-vocabulary rate)
|
| 164 |
|
| 165 |
### Results
|
| 166 |
|
|
|
|
| 168 |
|
| 169 |
#### Summary
|
| 170 |
|
| 171 |
+
This tokenizer is expected to produce more efficient, code-aware tokenization for Python source code compared to the original GPT-2 tokenizer, though formal benchmark results have not yet been recorded.
|
| 172 |
|
| 173 |
## Model Examination [optional]
|
| 174 |
|
|
|
|
| 192 |
|
| 193 |
### Model Architecture and Objective
|
| 194 |
|
| 195 |
+
Byte-level BPE tokenizer following the GPT-2 tokenizer architecture, retrained on a new corpus (Python code from `code_search_net`) rather than the original GPT-2 training data.
|
| 196 |
|
| 197 |
### Compute Infrastructure
|
| 198 |
|
|
|
|
| 204 |
|
| 205 |
#### Software
|
| 206 |
|
| 207 |
+
- 🤗 `transformers`
|
| 208 |
+
- 🤗 `datasets`
|
| 209 |
+
- 🤗 `tokenizers`
|
| 210 |
|
| 211 |
## Citation [optional]
|
| 212 |
|
|
|
|
| 214 |
|
| 215 |
**BibTeX:**
|
| 216 |
|
| 217 |
+
```bibtex
|
| 218 |
+
@misc{husain2019codesearchnet,
|
| 219 |
+
title={CodeSearchNet Challenge: Evaluating the State of Semantic Code Search},
|
| 220 |
+
author={Husain, Hamel and Wu, Ho-Hsiang and Gazit, Tiferet and Allamanis, Miltiadis and Brockschmidt, Marc},
|
| 221 |
+
year={2019},
|
| 222 |
+
eprint={1909.09436},
|
| 223 |
+
archivePrefix={arXiv}
|
| 224 |
+
}
|
| 225 |
+
```
|
| 226 |
|
| 227 |
**APA:**
|
| 228 |
|
| 229 |
+
Husain, H., Wu, H.-H., Gazit, T., Allamanis, M., & Brockschmidt, M. (2019). CodeSearchNet Challenge: Evaluating the State of Semantic Code Search. arXiv preprint arXiv:1909.09436.
|
| 230 |
|
| 231 |
## Glossary [optional]
|
| 232 |
|
| 233 |
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
| 234 |
|
| 235 |
+
- **BPE (Byte-Pair Encoding):** A subword tokenization algorithm that iteratively merges the most frequent pairs of bytes/characters to build a vocabulary.
|
| 236 |
+
- **`train_new_from_iterator`:** A 🤗 Transformers method that allows retraining an existing tokenizer's vocabulary on a new corpus while keeping the same tokenization algorithm/architecture.
|
| 237 |
|
| 238 |
## More Information [optional]
|
| 239 |
|
|
|
|
| 241 |
|
| 242 |
## Model Card Authors [optional]
|
| 243 |
|
| 244 |
+
farid678
|
| 245 |
|
| 246 |
## Model Card Contact
|
| 247 |
|
| 248 |
+
https://huggingface.co/farid678
|