Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

red-candle

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

red-candle

  • 0.0.4
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

red-candle

build Gem Version

🕯️ candle - Minimalist ML framework - for Ruby

Usage

require "candle"

x = Candle::Tensor.new([1, 2, 3, 4, 5, 6], :i64)
x = x.reshape([3, 2])
# [[1., 2.],
#  [3., 4.],
#  [5., 6.]]
# Tensor[[3, 2], f32]
require 'candle'
model = Candle::Model.new
embedding = model.embedding("Hi there!")

A note on memory usage

The Candle::Model defaults to the jinaai/jina-embeddings-v2-base-en model with the sentence-transformers/all-MiniLM-L6-v2 tokenizer (both from HuggingFace). With this configuration the model takes a little more than 3GB of memory running on my Mac. The memory stays with the instantiated Candle::Model class, if you instantiate more than one, you'll use more memory. Likewise, if you let it go out of scope and call the garbage collector, you'll free the memory. For example:

> require 'candle'
# Ruby memory = 25.9 MB
> model = Candle::Model.new
# Ruby memory = 3.50 GB
> model2 = Candle::Model.new
# Ruby memory = 7.04 GB
> model2 = nil
> GC.start
# Ruby memory = 3.56 GB
> model = nil
> GC.start
# Ruby memory = 55.2 MB

A note on returned embeddings

The code should match the same embeddings when generated from the python transformers library. For instance, locally I was able to generate the same embedding for the text "Hi there!" using the python code:

from transformers import AutoModel
model = AutoModel.from_pretrained('jinaai/jina-embeddings-v2-base-en', trust_remote_code=True)
sentence = ['Hi there!']
embedding = model.encode(sentence)
print(embedding)

And the following ruby:

require 'candle'
model = Candle::Model.new
embedding = model.embedding("Hi there!")

Development

FORK IT!

git clone https://github.com/your_name/red-candle
cd red-candle
bundle
bundle exec rake compile

Implemented with Magnus, with reference to Polars Ruby

Policies

  • The less code, the better.
  • Ideally, the PyPO3 code should work as is.
  • Error handling is minimal.

Pull requests are welcome.

kojix2 started this project to learn Rust, but does not necessarily have enough time to maintain this library. If you are interested in becoming a project owner or committer, please send me a pull request.

See Also

FAQs

Package last updated on 08 Apr 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc