Skip to main content

A library containing common functions developers used to write repetitevly

Project description

Utility Library

A collection of utility functions for file operations, text processing, AI, and machine learning, designed to streamline common tasks in PyTorch projects.

Features

  • Load and save JSON and YAML files.
  • Text processing utilities including tokenization and normalization.
  • Device management for PyTorch (CPU, CUDA, or MPS).
  • Similarity computation for embeddings using cosine similarity.
  • Utility functions for data manipulation such as moving averages, safe division, and flattening dictionaries.

Installation

You can install the library via pip:

pip install FuncHub

Usage

File Operations

Load YAML File

from pytorch_utility_library import open_yaml

config = open_yaml('config.yaml', key='model')

Load JSON File

from pytorch_utility_library import open_json

data = open_json('data.json')

Save Data to JSON

from pytorch_utility_library import dump_to_json

dump_to_json('output.json', data)

Save Text to File

from pytorch_utility_library import dump_to_text

dump_to_text('Hello, World!', 'output/hello.txt')

Text Processing

Tokenize Text

from pytorch_utility_library import tokenize

tokens = tokenize("Hello, how are you?")

Normalize Text

from pytorch_utility_library import normalize_text

normalized = normalize_text("  Hello,   How Are You?  ")

AI and Machine Learning

Get Device

from pytorch_utility_library import get_device

device = get_device()
print(f"Using device: {device}")

Compute Cosine Similarity

from pytorch_utility_library import compute_similarity

similarity = compute_similarity(embedding1, embedding2)

Utility Functions

Calculate Moving Average

from pytorch_utility_library import moving_average

averages = moving_average([1, 2, 3, 4, 5], window_size=3)

Flatten a Nested Dictionary

from pytorch_utility_library import flatten_dict

flat_dict = flatten_dict({'a': {'b': 1, 'c': 2}, 'd': 3})

Logging

The library uses a custom logger for error and information logging. Make sure to configure the logger in your application as needed.

Contributing

Contributions are welcome!

License

This project is licensed under the MIT License - 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

funchub-0.1.4.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

FuncHub-0.1.4-py3-none-any.whl (5.0 kB view details)

Uploaded Python 3

File details

Details for the file funchub-0.1.4.tar.gz.

File metadata

  • Download URL: funchub-0.1.4.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for funchub-0.1.4.tar.gz
Algorithm Hash digest
SHA256 c5899a6102570a0ab25d2ee7638249ab21b46257297cdba3c49f9cdb53da8b03
MD5 f5a633f1457486b704757bcbeeb1a4f8
BLAKE2b-256 6d8a6e01da3f721c9d1f46b11a03ed09d212ff66979945ba52b660eca1a7107b

See more details on using hashes here.

File details

Details for the file FuncHub-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: FuncHub-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 5.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for FuncHub-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 8f322e1f6b565ef339f8f9b2f0f698774b79505fbb6ea5fd41dd689e6ed82fc1
MD5 bb76fe728bbbe910928a0158b2cfc6c7
BLAKE2b-256 f7a7ca2239fca6d5b46b8033eb0cf149afca4d27cbaee3710a5dba0dbdef65bc

See more details on using hashes here.

Supported by

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