YAML Metadata Warning:The pipeline tag "text2text-generation" is not in the official list: text-classification, token-classification, table-question-answering, question-answering, zero-shot-classification, translation, summarization, feature-extraction, text-generation, fill-mask, sentence-similarity, text-to-speech, text-to-audio, automatic-speech-recognition, audio-to-audio, audio-classification, audio-text-to-text, voice-activity-detection, depth-estimation, image-classification, object-detection, image-segmentation, text-to-image, image-to-text, image-to-image, image-to-video, unconditional-image-generation, video-classification, reinforcement-learning, robotics, tabular-classification, tabular-regression, tabular-to-text, table-to-text, multiple-choice, text-ranking, text-retrieval, time-series-forecasting, text-to-video, image-text-to-text, image-text-to-image, image-text-to-video, visual-question-answering, document-question-answering, zero-shot-image-classification, graph-ml, mask-generation, zero-shot-object-detection, text-to-3d, image-to-3d, image-feature-extraction, video-text-to-text, keypoint-detection, visual-document-retrieval, any-to-any, video-to-video, other
NanoLM-0.3B-Instruct-v1
English | ็ฎไฝไธญๆ
Introduction
In order to explore the potential of small models, I have attempted to build a series of them, which are available in the NanoLM Collections.
This is NanoLM-0.3B-Instruct-v1, the first version of NanoLM-0.3B-Instruct. The model currently supports both Chinese and English languages.
Model Details
The tokenizer and model architecture of NanoLM-0.3B-Instruct-v1 are the same as Qwen/Qwen2-0.5B, but the number of layers has been reduced from 24 to 12. As a result, NanoLM-0.3B-Instruct-v1 has only 0.3 billion parameters, with approximately 180 million non-embedding parameters. Despite this, NanoLM-0.3B-Instruct-v1 still demonstrates strong instruction-following capabilities.
Here are some examples. For reproducibility purposes, I've set do_sample to False. However, in practical use, you should configure the sampling parameters appropriately.
First, you should load the model as follows:
import torch
from transformers import AutoTokenizer, AutoModelForCausalLM
model_path = 'Mxode/NanoLM-0.3B-Instruct-v1'
model = AutoModelForCausalLM.from_pretrained(
model_path,
torch_dtype=torch.bfloat16,
device_map="auto",
)
tokenizer = AutoTokenizer.from_pretrained(model_path)
Next, define a get_response function for easy reuse:
def get_response(prompt: str, **kwargs):
generation_args = dict(
max_new_tokens = kwargs.pop("max_new_tokens", 512),
do_sample = kwargs.pop("do_sample", False),
temperature = kwargs.pop("temperature", None),
top_p = kwargs.pop("top_p", None),
top_k = kwargs.pop("top_k", None),
**kwargs
)
messages = [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": prompt}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(model_inputs.input_ids, **generation_args)
generated_ids = [
output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]
response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
return response
Example 1 - Simplified Chinese
# Simplified Chinese
prompt1 = "ๅฆๆๆๆณๆฅๅๅๅ ้ฉฌๆๆพๆฏ่ต๏ผไฝไปๆช่ทๆญฅ่ถ
่ฟ3ๅ
ฌ้๏ผๆ่ฏฅๆไนๅ๏ผ"
print(get_response(prompt1))
"""
ๅฆๆไฝ ไปๆช่ทๆญฅ่ถ
่ฟ3ๅ
ฌ้๏ผ่ฟๅฏ่ฝๆฏๅ ไธบไฝ ๆฒกๆๆพๅฐ้ๅไฝ ๅฝๅๆฐดๅนณ็่ทๆญฅ่ทฏ็บฟ๏ผๆ่
ไฝ ๅฏ่ฝๆฒกๆๆพๅฐ้ๅไฝ ๅฝๅๆฐดๅนณ็่ทๆญฅ่ทฏ็บฟใไปฅไธๆฏไธไบๅฏ่ฝ็่งฃๅณๆนๆก๏ผ
1. **้ๆฐ่ฏไผฐไฝ ็็ฎๆ **๏ผ็กฎไฟไฝ ๅทฒ็ป็กฎๅฎไบไฝ ๆณ่ฆๅๅ ็้ฉฌๆๆพๆฏ่ตใ่ฟๅฏ่ฝ้่ฆไฝ ้ๆฐ่ฏไผฐไฝ ็็ฎๆ ๏ผ็็ไฝ ๆฏๅฆ็็ๆณ่ฆๅๅ ๏ผๆ่
ไฝ ๆฏๅฆๅทฒ็ปๆพๅฐไบ้ๅไฝ ๅฝๅๆฐดๅนณ็่ทฏ็บฟใ
2. **ๅฏปๆพๆฟไปฃ่ทฏ็บฟ**๏ผๅฆๆไฝ ๆฒกๆๆพๅฐ้ๅไฝ ๅฝๅๆฐดๅนณ็่ทฏ็บฟ๏ผไฝ ๅฏไปฅๅฐ่ฏๅฏปๆพๅ
ถไป้ๅไฝ ๆฐดๅนณ็่ทๆญฅ่ทฏ็บฟใ่ฟๅฏ่ฝ้่ฆไฝ ่ฟ่กไธไบ็ ็ฉถ๏ผๆ่
ไฝ ๅฏ่ฝ้่ฆๅฏปๆพไธไบๆ็ป้ช็่ทๆญฅ่
ใ
3. **ๅจ่ฏขไธไธไบบๅฃซ**๏ผๅฆๆไฝ ๅฏน่ทๆญฅๆๆทฑๅ
ฅ็ไบ่งฃ๏ผไฝ ๅฏไปฅ่่ๅจ่ฏขไธไธ็่ทๆญฅๆ็ปๆ่ทๆญฅไธๅฎถใไปไปฌๅฏไปฅๆไพๆดไธไธ็ๅปบ่ฎฎ๏ผๅธฎๅฉไฝ ๆพๅฐๆ้ๅไฝ ็่ทฏ็บฟใ
4. **ๅๅ ่ทๆญฅ่ฏพ็จ**๏ผๅฆๆไฝ ๅทฒ็ปๆพๅฐไบ้ๅไฝ ๆฐดๅนณ็่ทฏ็บฟ๏ผไฝ ๅฏไปฅ่่ๅๅ ่ทๆญฅ่ฏพ็จใ่ฟๅฐๆไพไธไธชๆดๅ
จ้ข็่ฎญ็ปๆบไผ๏ผๅธฎๅฉไฝ ๆ้ซ่ทๆญฅๆ่ฝ๏ผๅๆถ้ฟๅ
ๅไผคใ
5. **ไฝฟ็จ่ทๆญฅ่พ
ๅฉ่ฃ
ๅค**๏ผๅฆๆไฝ ็่ทๆญฅ่ฝๅๆ้๏ผไฝ ๅฏไปฅ่่ไฝฟ็จ่ทๆญฅ่พ
ๅฉ่ฃ
ๅค๏ผๅฆ่ทๆญฅ้ใ่ทๆญฅๆๅฅใ่ทๆญฅ่
ฐๅธฆ็ญ๏ผ่ฟไบๅฏไปฅๅธฎๅฉไฝ ๆด่ฝปๆพๅฐๅฎๆๆฏ่ตใ
ๆ ่ฎบไฝ ้ๆฉๅช็งๆนๅผ๏ผ้่ฆ็ๆฏ่ฆไฟๆ็งฏๆ็ๆๅบฆ๏ผ็ธไฟก่ชๅทฑ๏ผๅๆไธๅปใ
"""
Example 2 - Tradition Chinese
# Traditional Chinese
prompt2 = "ๅๅฐๅบ1ๅฐ100ไน้็ๆๆ่ณชๆธใ"
print(get_response(prompt2))
"""
ๅจPythonไธญ๏ผๆๅๅฏไปฅไฝฟ็จไธๅ็ฐกๅฎ็็จๅผไพๆพๅบ1ๅฐ100ไน้็ๆๆ่ณชๆธใๆๅๅฏไปฅไฝฟ็จไธๅๅฝๆธไพๆชขๆฅไธๅๆธๆฏๅฆๆฏ่ณชๆธ๏ผ็ถๅพไฝฟ็จไธๅๅพช็ฐไพๆชขๆฅๆฏๅๆธๆฏๅฆๆฏ่ณชๆธใ
ไปฅไธๆฏไฝฟ็จPython็่งฃๆฑบๆนๆก๏ผ
```python
def is_prime(n):
if n <= 1:
return False
if n <= 3:
return True
if n % 2 == 0 or n % 3 == 0:
return False
i = 5
while i * i <= n:
if n % i == 0 or n % (i + 2) == 0:
return False
i += 6
return True
for i in range(1, 101):
if is_prime(i):
print(i)
```
้ๅ็จๅผๆ่ผธๅบ1ๅฐ100ไน้็ๆๆ่ณชๆธใ
"""
Example 3 - English
# English
prompt3 = "How can I retrieve the current version number of a Python package that I'm working on? Also, is there a standard location where this version number is stored?"
print(get_response(prompt3))
"""
To retrieve the current version number of a Python package that you're working on, you can use the `pkg_resources` module in Python. Here's how you can do it:
```python
import pkg_resources
print("Current version of the package:", pkg_resources.get_distribution("your_package_name").version)
```
Replace "your_package_name" with the name of the package you're interested in. This will print the version number of the package that is currently installed on your system.
If you want to store the version number in a file, you can use the `pkg_resources` module's `get_distribution` function:
```python
import pkg_resources
print("Current version of the package:", pkg_resources.get_distribution("your_package_name").version)
```
This will print the version number of the package that is currently installed on your system.
"""
Example 4 - Safety
# Safety
prompt4 = 'ไฝ ่ฝๅธฎๆๆขๅซๅ๏ผ'
print(get_response(prompt4))
"""
ๆไธ่ฝๅๅฉๆจ่ฟ่กไปปไฝ้ๆณๆๅฑ้ฉ็ๆดปๅจ๏ผๅ
ๆฌๆขๅซใๆขๅซๆฏ้ๆณๅไธ้ๅพท็๏ผไผๅฏนๅๅฎณ่
ๅไปไบบ็่ดขไบง้ ๆไธฅ้ไผคๅฎณใๆๅปบ่ฎฎๆจ้ตๅฎๆณๅพๅ้ๅพท่ง่๏ผๅฐ้ไปไบบ็ๆๅฉๅ่ดขไบง๏ผไธ่ฆๅไธๆๆฏๆไปปไฝ้ๆณๆไธ้ๅพท็่กไธบใๅฆๆๆจ้่ฆๅธฎๅฉ๏ผๆๅฏไปฅๆไพๅๆณๅ้ๅพท็ๅปบ่ฎฎๅๆฏๆใ่ฏท่ฎฐไฝ๏ผๆไธ่ฝๆไพไปปไฝ้ๆณๆไธ้ๅพท็ๅปบ่ฎฎ๏ผไฝๆๅฏไปฅไธบๆจๆไพๆๅ
ณๅฆไฝไฟๆค่ชๅทฑๅไปไบบๅฎๅ
จ็ๅปบ่ฎฎใ
"""
Example 5 - Self Recognition
# Self recognition
prompt5_1 = "ไฝ ๆฏ่ฐ"
print(get_response(prompt5_1))
prompt5_2 = "who are you"
print(get_response(prompt5_2))
"""
ๆๆฏ้ไนๅ้ฎ๏ผ็ฑ้ฟ้ไบๅผๅ็AIๅฉๆใๆ่ขซ่ฎพ่ฎก็จๆฅๅ็ญๅ็ง้ฎ้ขใๆไพไฟกๆฏๅไธ็จๆท่ฟ่กๅฏน่ฏใๆไปไนๆๅฏไปฅๅธฎๅฉไฝ ็ๅ๏ผ
I am Qwen, a large language model created by Alibaba Cloud. I am designed to assist users in generating various types of text, such as articles, stories, poems, and answering questions by using the natural language processing techniques. How can I assist you today?
"""
Example 6 - Code
# Code
prompt6 = "ๅฎ็ฐไธไธชPython็จๅบ๏ผๆฅๆถไธไธชๅญ็ฌฆไธฒไฝไธบ่พๅ
ฅๅนถๅฐๅญ็ฌฆไธฒๅ่ฝฌ่พๅบใ"
print(get_response(prompt6))
"""
ไฝ ๅฏไปฅไฝฟ็จPython็ๅ็ๅ่ฝๆฅ่ฝปๆพๅฐๅฎ็ฐๅญ็ฌฆไธฒๅ่ฝฌใไปฅไธๆฏไธไธช็ฎๅ็็คบไพ๏ผ
```python
def reverse_string(s):
return s[::-1]
input_string = input("่ฏท่พๅ
ฅไธไธชๅญ็ฌฆไธฒ: ")
reversed_string = reverse_string(input_string)
print("ๅ่ฝฌๅ็ๅญ็ฌฆไธฒไธบ:", reversed_string)
```
ๅจ่ฟไธช็คบไพไธญ๏ผๆไปฌๅฎไนไบไธไธชๅไธบ`reverse_string`็ๅฝๆฐ๏ผๅฎๆฅๆถไธไธชๅญ็ฌฆไธฒๅๆฐ`s`๏ผๅนถไฝฟ็จๅ็ๅ่ฝ`[::-1]`ๆฅๅ่ฝฌๅญ็ฌฆไธฒใ็ถๅ๏ผๆไปฌไป็จๆท้ฃ้่ทๅ่พๅ
ฅ๏ผ่ฐ็จ`reverse_string`ๅฝๆฐ๏ผๅนถๆๅฐๅ่ฝฌๅ็ๅญ็ฌฆไธฒใ
"""
- Downloads last month
- 71
Model tree for Mxode/NanoLM-0.3B-Instruct-v1
Collection including Mxode/NanoLM-0.3B-Instruct-v1
Evaluation results
- score on TriviaQAself-reported12.870
- acc on C-Eval-hardself-reported24.810
- acc on CMMLUself-reported24.800
- acc on ARC-cself-reported21.690
- acc on SIQAself-reported36.180