SmolLM2 and Smol-tools by Hugging Face: A Beginner's Guide

Updated on
6 min read

As AI models grow in size and complexity, deploying them in resource-constrained environments can be challenging. Hugging Face’s SmolLM2-1.7B Instruct and smol-tools aim to address this by offering efficient, lightweight models and tools that run locally without requiring high-end hardware or internet access. This guide will introduce you to SmolLM2 and smol-tools, explain their usage, and help you get started.

SmolLM2 and Smol-tools by Hugging Face: A Beginner's Guide

What is SmolLM2?

SmolLM2-1.7B Instruct is a small yet powerful language model built using LLaMA.cpp, optimized for running on local devices without extensive computational resources. With 1.7 billion parameters, SmolLM2 is versatile enough for most NLP tasks while remaining accessible to devices with limited memory and processing power.

SmolLM2 is a compact language model series released by Hugging Face, aimed at offering competitive natural language processing capabilities while maintaining a small footprint suitable for on-device deployment. The SmolLM2 lineup includes models with 135M, 360M, and 1.7B parameters, showing strong advancements over its predecessor, SmolLM1. Particularly, SmolLM2 models demonstrate better instruction-following, reasoning, and general knowledge retention.

Key Features of SmolLM2

  1. Small but Effective: At 1.7 billion parameters, SmolLM2 achieves a balance between model size and efficiency, enabling it to run on CPUs.
  2. Optimized for Low-Power Devices: Specifically designed to work on systems with minimal resources, such as laptops or mobile devices.
  3. Quantized for Efficiency: Using 16-bit floating-point (F16) for efficient inference, making it suitable even for lower-spec systems.
  4. Instruction-Following Capability: SmolLM2 can follow user instructions for tasks like text summarization, rewriting, and answering questions.

The SmolLM2 models were trained on an impressive dataset of 4 trillion tokens that includes sources like FineWeb-Edu, DCLM, and The Stack, along with new filtered datasets created specifically for this release. Additionally, they underwent fine-tuning with Direct Preference Optimization (DPO) for more efficient performance in user-aligned tasks, allowing them to handle rewriting, summarization, and function-calling tasks efficiently.

For more information, read the official announcement by Hugging Face

What are Smol-tools?

Smol-tools is a collection of lightweight, AI-powered tools that enhance the utility of SmolLM2 and other small language models. Built with LLaMA.cpp, smol-tools enables a range of NLP tasks without requiring internet access or GPUs, making it ideal for local, offline applications.

Key Features of Smol-tools

The smol-tools suite includes:

  • SmolSummarizer: Quickly generates concise summaries of text, retaining essential points. Capable of answering follow-up questions based on the summarized content.

  • SmolRewriter: Enhances text readability by rephrasing content to appear more professional while preserving its original intent, ideal for email or message drafting.

  • SmolAgent: An AI agent designed to perform tasks by integrating external tools. It includes:

    • Weather Lookup: Provides weather updates for specified locations.
    • Random Number Generation: Offers random numbers for quick testing or interactive applications.
    • Current Time: Returns the current time.
    • Web Browser Control: Supports basic browser control for web-based tasks.
    • Extensible Tool System: Developers can integrate additional tools into SmolAgent for custom functionality.

Getting Started with SmolLM2 and Smol-tools

To begin working with SmolLM2 and smol-tools, follow these setup instructions.

Step 1: System Requirements

Before installing, make sure your system meets the following requirements:

  • Operating System: Windows, macOS, or Linux
  • CPU: Dual-core minimum
  • Memory: 4 GB RAM (8 GB recommended)
  • GPU: Optional; CUDA-enabled NVIDIA GPUs will improve performance
  • Storage: 1 GB for initial installation, with potential expansion based on usage

Step 2: Installation

To set up SmolLM2 and smol-tools, clone the repository and install necessary dependencies:

git clone https://github.com/huggingface/smollm.git
cd smollm/smol_tools
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt

For systems that need additional dependencies, such as tkinter for macOS and Linux, follow these installation commands:

Step 3: Running the Tkinter GUI Demo

The smol-tools package includes a Tkinter-based demo app that provides easy access to the tools via keyboard shortcuts:

python demo_tkinter.py

Shortcuts within the demo:

  • F1: Open SmolDraft for drafting
  • F2: Summarize selected text
  • F5: Open SmolChat for chatting
  • F10: Access SmolAgent for AI-powered assistance

Step 4: Programmatic Usage

Developers can directly integrate SmolLM2 and smol-tools into Python applications:

from smol_tools.summarizer import SmolSummarizer
from smol_tools.rewriter import SmolRewriter
from smol_tools.agent import SmolToolAgent

# Initialize tools
summarizer = SmolSummarizer()
rewriter = SmolRewriter()
agent = SmolToolAgent()

# Use the summarizer
for summary in summarizer.process("Your text here"):
    print(summary)

# Use the rewriter
for improved in rewriter.process("Your text here"):
    print(improved)

# Use the agent
for response in agent.process("What's the weather in London?"):
    print(response)

Potential Drawbacks of SmolLM2 and Smol-tools

While generally strong, SmolLM2 models do have some limitations; they are primarily optimized for English and may not always produce factually accurate or unbiased responses. Evaluations show that, in many tasks, the SmolLM2 models surpass other small-scale language models like Qwen-2.5-0.5B in zero-shot and few-shot tasks, such as HellaSwag and ARC (Average). The most optimized 360M version performs well on typical reasoning and commonsense tasks, making it a reliable choice for various NLP applications that require efficiency and scalability on modest hardware setups.

Some limitations worth noting:

  1. Simpler Model Performance: The model’s performance may be limited in handling complex or nuanced tasks compared to larger language models.
  2. Resource Scaling: While smol-tools are ideal for smaller applications, they may struggle to handle the demands of large, enterprise-level deployments.
  3. Manual Fine-Tuning Needed: SmolLM2 may require further fine-tuning for domain-specific tasks, potentially impacting efficiency.

Applications of SmolLM2 and Smol-tools

SmolLM2 and smol-tools are ideal for applications where computational resources are constrained:

  • Edge Devices: Perfect for low-power devices like Raspberry Pi.
  • Offline Systems: Smol-tools can run without internet access, ideal for secure environments.
  • Prototyping: Quick deployment in MVPs or prototypes.
  • Interactive Kiosks: Useful in customer service applications that require local NLP capabilities.

Conclusion

SmolLM2 and smol-tools by Hugging Face make powerful NLP capabilities accessible in resource-limited environments, providing a lightweight solution for developers who need high-performance language models without the need for extensive hardware. With a suite of efficient tools, SmolLM2 and smol-tools open doors for AI in areas where high computational costs have been a barrier. This guide should help you get started with SmolLM2 and smol-tools, bringing the power of AI to smaller, more accessible devices.

TBO Editorial

About the Author

TBO Editorial writes about the latest updates about products and services related to Technology, Business, Finance & Lifestyle. Do get in touch if you want to share any useful article with our community.