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
Safetensors
Model size
0.3B params
Tensor type
BF16
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Model tree for Mxode/NanoLM-0.3B-Instruct-v1

Quantizations
1 model

Collection including Mxode/NanoLM-0.3B-Instruct-v1

Evaluation results