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.9.9.tar.gz (100.2 kB view details)

Uploaded Source

Built Distribution

LangTorch-0.9.9-py3-none-any.whl (106.5 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for LangTorch-0.9.9.tar.gz
Algorithm Hash digest
SHA256 9e11edb4cf4f4b1e58f94ddf5db47193930725977af9cf436299d6d33e3a438f
MD5 c75ae3ab2cbc1925f43ab1a1e9e74c37
BLAKE2b-256 3e8ee1fc387eb4fcbc32c304e95ae5e1f8f64bf23934380eac398023bdd5315c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: LangTorch-0.9.9-py3-none-any.whl
  • Upload date:
  • Size: 106.5 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.9.9-py3-none-any.whl
Algorithm Hash digest
SHA256 1fe434ddc198aeeac9132309706e49f69862d5278e2e7c7d54ab3189a67c7a4f
MD5 2814d83d07d1bec7101a050b9ed5bfbf
BLAKE2b-256 b841761933ae8ab990b1c78dc326919e99863bd1c2fa5f78ee5435433bdd547e

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