swift-transformers  by huggingface

Swift package for language model utilities in Swift apps

Created 2 years ago
1,095 stars

Top 34.8% 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

1 day ago

Responsiveness

1 week

Pull Requests (30d)
27
Issues (30d)
12
Star History
54 stars in the last 30 days

Explore Similar Projects

Starred by Luis Capelo Luis Capelo(Cofounder of Lightning AI), Eugene Yan Eugene Yan(AI Scientist at AWS), and
14 more.

text by pytorch

0.0%
4k
PyTorch library for NLP tasks
Created 8 years ago
Updated 1 week ago
Starred by Aravind Srinivas Aravind Srinivas(Cofounder of Perplexity), François Chollet François Chollet(Author of Keras; Cofounder of Ndea, ARC Prize), and
42 more.

spaCy by explosion

0.1%
32k
NLP library for production applications
Created 11 years ago
Updated 3 months ago
Feedback? Help us improve.