Skip to content

Instantly share code, notes, and snippets.

View sachaarbonel's full-sized avatar
👨‍💻
Uncovering bugs

Sacha Arbonel sachaarbonel

👨‍💻
Uncovering bugs
View GitHub Profile
@sachaarbonel
sachaarbonel / gist:4276ae8f26064d9f36324f0626521fc0
Created August 17, 2024 14:04
Languages supported by facebook/wav2vec2-lv-60-espeak-cv-ft
ab: Abkhaz
ar: Arabic
as: Assamese
br: Breton
ca: Catalan
cnh: Hakha Chin
cs: Czech
cv: Chuvash
cy: Welsh
de: German
fn main() -> anyhow::Result<()> {
let model = SentenceEmbeddingsBuilder::remote(SentenceEmbeddingsModelType::AllMiniLmL12V2).create_model()?;
let json = fs::read_to_string("data/books.json")?;
let library: Library = serde_json::from_str(&json)?;
let mut embeddedbooks = Vec::new();
for book in library.books.clone() {
println!("Embedding book: {}", book.title);
let embeddings = model.encode(&[book.clone().summary])?;
let embedding = to_array(embeddings[0].as_slice());
impl EmbeddedBook {
fn topic(embeddings: [f32; 384]) -> Self {
Self {
title: None,
author: None,
summary: None,
embeddings: embeddings,
}
}
}
fn main() -> anyhow::Result<()> {
let model = SentenceEmbeddingsBuilder::remote(SentenceEmbeddingsModelType::AllMiniLmL12V2).create_model()?;
let json = fs::read_to_string("data/books.json")?;
let library: Library = serde_json::from_str(&json)?;
let mut embeddedbooks = Vec::new();
for book in library.books.clone() {
println!("Embedding book: {}", book.title);
let embeddings = model.encode(&[book.clone().summary])?;
let embedding = to_array(embeddings[0].as_slice());
impl KdPoint for EmbeddedBook {
type Scalar = f32;
type Dim = typenum::U2; // 2 dimensional tree.
fn at(&self, k: usize) -> f32 {
self.embeddings[k]
}
}
fn main() -> anyhow::Result<()> {
+ let model = SentenceEmbeddingsBuilder::remote(SentenceEmbeddingsModelType::AllMiniLmL12V2).create_model()?;
let json = fs::read_to_string("data/books.json")?;
let library: Library = serde_json::from_str(&json)?;
+ let mut embeddedbooks = Vec::new();
for book in library.books.clone() {
- println!("Embedding book: {}", book.title);
+ let embeddings = model.encode(&[book.clone().summary])?;
+ let embedding = to_array(embeddings[0].as_slice());
#[derive(Debug)]
pub struct EmbeddedBook {
pub title: String,
pub author: String,
pub summary: String,
pub embeddings: [f32; 384],
}
fn main() -> anyhow::Result<()> {
let json = fs::read_to_string("data/books.json")?;
let library: Library = serde_json::from_str(&json)?;
for book in library.books.clone() {
println!("Embedding book: {}", book.title);
}
Ok(())
}
use serde::{Deserialize};
#[derive(Debug, Deserialize)]
pub struct Library {
pub books: Vec<Book>,
}
#[derive(Debug, Deserialize, Clone)]
pub struct Book {
pub title: String,
{
"books": [
{
"title": "The Great Gatsby",
"author": "F. Scott Fitzgerald",
"summary": "The story primarily concerns the young and mysterious millionaire Jay Gatsby and his quixotic passion and obsession with the beautiful former debutante Daisy Buchanan."
},
{
"title": "The Catcher in the Rye",
"author": "J. D. Salinger",