swift-transformers  by huggingface

Swift package for language model utilities in Swift apps

created 2 years ago
1,031 stars

Top 37.0% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This Swift package provides utilities for integrating large language models into Swift applications, mirroring the Python transformers API with an idiomatic Swift interface. It targets Swift developers seeking to leverage state-of-the-art NLP models without requiring prior Python or ML expertise, offering simplified model interaction and data handling.

How It Works

The library is modular, featuring Tokenizers for text-to-token conversion with chat template support, Hub for downloading models and configurations from Hugging Face, and Generation for text generation algorithms (greedy search, top-k, top-p sampling). Model inference is primarily handled via a Models module that abstracts Core ML packages, enabling efficient on-device execution.

Quick Start & Requirements

  • Install via Swift Package Manager: Add https://github.com/huggingface/swift-transformers as a dependency in Package.swift.
  • Prerequisites: Core ML for model inference; Tokenizers and Hub modules do not require Core ML. Tested with autoregressive models like GPT, Llama 2, Falcon, etc. Encoder-decoder models (T5, Flan) are not supported.
  • Resources: Inference performance depends on the Core ML model used.
  • Links: Announcement Post, Usage Examples, Core ML Conversion

Highlighted Details

  • Idiomatic Swift API, abstracting complex ML concepts.
  • Supports Hugging Face Hub for model discovery and download.
  • Includes text generation strategies: greedy search, top-k, and top-p sampling.
  • Facilitates on-device inference via Core ML integration.

Maintenance & Community

  • Community project with contributions welcomed.
  • Issues tagged "good first issue" available for new contributors.
  • Tests can be run with swift test.

Licensing & Compatibility

  • License: Apache 2.0.
  • Compatibility: Suitable for commercial use and integration into closed-source applications.

Limitations & Caveats

Encoder-decoder models such as T5 and Flan are not currently supported. The package focuses on autoregressive models and Core ML inference.

Health Check
Last commit

3 days ago

Responsiveness

1 week

Pull Requests (30d)
6
Issues (30d)
2
Star History
99 stars in the last 90 days

Explore Similar Projects

Starred by Lilian Weng Lilian Weng(Cofounder of Thinking Machines Lab), Andrej Karpathy Andrej Karpathy(Founder of Eureka Labs; Formerly at Tesla, OpenAI; Author of CS 231n), and
42 more.

transformers by huggingface

0.2%
148k
ML library for pretrained model inference and training
created 6 years ago
updated 19 hours ago
Feedback? Help us improve.