-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from akshayballal95/main
New Features
- Loading branch information
Showing
27 changed files
with
1,678 additions
and
167 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import embed_anything | ||
import time | ||
start_time = time.time() | ||
data = embed_anything.embed_directory("test_files", embeder= "Bert") | ||
data = embed_anything.embed_directory("test_files", embeder= "Bert", extensions=["pdf"]) | ||
print(data[0]) | ||
end_time = time.time() | ||
print("Time taken: ", end_time-start_time) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use embed_anything::file_processor::website_processor; | ||
use candle_core::Tensor; | ||
|
||
#[tokio::main] | ||
async fn main() { | ||
let url = "https://en.wikipedia.org/wiki/Long_short-term_memory"; | ||
|
||
let website_processor = website_processor::WebsiteProcesor; | ||
let webpage = website_processor.process_website(url).await.unwrap(); | ||
let embeder = embed_anything::embedding_model::bert::BertEmbeder::default(); | ||
let embed_data = webpage.embed_webpage(&embeder).await.unwrap(); | ||
let embeddings: Vec<Vec<f32>> = embed_data.iter().map(|data| data.embedding.clone()).collect(); | ||
|
||
let embeddings = Tensor::from_vec( | ||
embeddings.iter().flatten().cloned().collect::<Vec<f32>>(), | ||
(embeddings.len(), embeddings[0].len()), | ||
&candle_core::Device::Cpu, | ||
).unwrap(); | ||
|
||
let query = vec!["how to use lstm for nlp".to_string()]; | ||
let query_embedding: Vec<f32> = embeder.embed(&query, None).await.unwrap().iter().map(|data| data.embedding.clone()).flatten().collect(); | ||
|
||
let query_embedding_tensor = Tensor::from_vec( | ||
query_embedding.clone(), | ||
(1, query_embedding.len()), | ||
&candle_core::Device::Cpu, | ||
).unwrap(); | ||
|
||
|
||
let similarities = embeddings | ||
.matmul(&query_embedding_tensor.transpose(0, 1).unwrap()) | ||
.unwrap() | ||
.detach() | ||
.squeeze(1) | ||
.unwrap() | ||
.to_vec1::<f32>() | ||
.unwrap(); | ||
|
||
let max_similarity_index = similarities.iter().enumerate().max_by(|a, b| a.1.partial_cmp(b.1).unwrap()).unwrap().0; | ||
let data = &embed_data[max_similarity_index]; | ||
|
||
println!("{:?}", data); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.