Skip to main content

Framework for intuitive LLM application development with tensors.

Project description

LangTorch Logo LangTorch

Release Notes Downloads License: MIT Twitter GitHub star chart

LangTorch is a Python package designed to simplify the development of LLM applications by leveraging familiar PyTorch concepts.

Installation

pip install langtorch

Overview

LangTorch provides a structured approach to LLM applications, offering:

  • TextTensors: A unified way to handle prompt templates, completion dictionaries, and chat histories.
  • TextModules: Building blocks, derived from torch.nn.Module, specifically tailored for text operations and LLM calls both locally and via an API.
  • other things that are also better than langchain

Examples

TextTensors

Creating and manipulating textual data as tensors:

template = TextTensor([["Explain {theory} in terms of {framework}"],  
                       ["Argue how {framework} can prove {theory}"]])  

result = template * TextTensor({"theory": "active inference", "framework": "thermodynamics" })

print(result)
# Outputs: [[Explain active inference in terms of thermodynamics]
#           [Argue how thermodynamics can prove active inference]]

TextModules

Building sequences of operations on text data:

chain = torch.nn.Sequential(
    TextModule("Calculate this equation: {}"),
    langtorch.methods.CoT,
    GPT4
    TextModule("Is this reasoning correct? {}", activation = GPT4)
)

output = chain(TextTensor(["170*32 =", "4*20 =", "123*45/10 =", "2**10*5 ="]))

Cosine Similarities

Compute similarities between entries:

from langtorch.tt import CosineSimilarity

cos = CosineSimilarity()
similarities = cos(TextTensor([["Yes"], ["No"]]), TextTensor(["1", "0", "Noo", "Yees"]))

Contribute

Your feedback and contributions are valued. Feel free to check out our contribution guidelines.

License

LangTorch is MIT licensed. See the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

LangTorch-0.1.7.tar.gz (85.8 kB view details)

Uploaded Source

Built Distribution

LangTorch-0.1.7-py3-none-any.whl (146.0 kB view details)

Uploaded Python 3

File details

Details for the file LangTorch-0.1.7.tar.gz.

File metadata

  • Download URL: LangTorch-0.1.7.tar.gz
  • Upload date:
  • Size: 85.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for LangTorch-0.1.7.tar.gz
Algorithm Hash digest
SHA256 fea71da6c6450af3d0f4f39c67cf1ba251a50ddcc547e5dfddb172c05d644eb8
MD5 04aa186479417ee009e64aae435532ac
BLAKE2b-256 1792f9247ca08613e967365314aef7f79724a03fdfe309fad24d557006739a35

See more details on using hashes here.

File details

Details for the file LangTorch-0.1.7-py3-none-any.whl.

File metadata

  • Download URL: LangTorch-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 146.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.3

File hashes

Hashes for LangTorch-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 1c4aeaa57a9223ab709f5d81c2ad19dcf3ce076e664cd3d05255d21cb24d20c9
MD5 cb5e2d2e1c84d942af7c20682d0bec39
BLAKE2b-256 1173b224a49abc8ae9d92ea94702eff23459955998cc7f9dac42e451521b4266

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page