from transformers import AutoTokenizer, AutoModel
defmean_pooling(token_embeddings, mask):
token_embeddings = token_embeddings.masked_fill(~mask[..., None].bool(), 0.)
sentence_embeddings = token_embeddings.sum(dim=1) / mask.sum(dim=1)[..., None]
return sentence_embeddings
# Remove pooling layer
model = AutoModel.from_pretrained("CarperAI/carptriever-1", add_pooling_layer=False)
tokenizer = AutoTokenizer.from_pretrained("CarperAI/carptriever-1")
sentences = [
"Where was Marie Curie born?", # Query"Maria Sklodowska, later known as Marie Curie, was born on November 7, 1867.",
"Born in Paris on 15 May 1859, Pierre Curie was the son of Eugène Curie, a doctor of French Catholic origin from Alsace."
]
# Apply tokenizer
inputs = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
# Encode sentences
outputs = model(**inputs)
embeddings = mean_pooling(outputs[0], inputs['attention_mask'])
# Compute dot-product scores between the query and sentence embeddings
query_embedding, sentence_embeddings = embeddings[0], embeddings[1:]
scores = (query_embedding @ sentence_embeddings.transpose(0, 1)).cpu().tolist()
sentence_score_pairs = sorted(zip(sentences[1:], scores), reverse=True)
print(f"Query: {sentences[0]}")
for sentence, score in sentence_score_pairs:
print(f"\nSentence: {sentence}\nScore: {score:.4f}")
Training data
Carptriever-1 is pre-trained on a de-duplicated subset of
The Pile
, a large and diverse dataset created by EleutherAI for language model training. This subset was created through a
Minhash LSH
process using a threshold of
0.87
.
Training procedure
The model was trained on 32 40GB A100 for approximately 100 hours with the following configurations:
Base model:
bert-large-uncased
Optimizer settings:
optimizer = AdamW
lr = 1e-5
schedule = linear
warmup = 20,000 steps
batch size = 2048
training steps = 150,000
MoCo settings:
queue size = 8192
momentum = 0.999
temperature = 0.05
Evaluation results
BEIR: Benchmarking IR
We report the following BEIR scores as measured in normalized discounted cumulative gain (nDCG@10):
Note that degradation in performance, relative to the Contriever model, was expected given the much broader diversity of our training dataset. We plan on addressing this in future updates with architectural improvements and view Carptriever-1 as our first iteration in the exploratory phase towards better language-embedding models.
CodeSearchNet Challenge Evaluating the State of Semantic Code Search
We provide results on the CodeSearchNet benchmark, measured in Mean Reciprocal Rank (MRR), following the code search procedure outlined in Section 3.3 of Neelakantan et al.'s
"Text and Code Embeddings by Contrastive Pre-Training"
.
Candidate Size = 1,000
Model
Avg
Python
Go
Ruby
PHP
Java
JS
Carptriever-1
60.24
65.85
63.29
62.1
59.1
55.52
55.55
Contriever
49.39
54.81
58.9
55.19
38.46
44.89
44.09
Candidate Size = 10,000
Model.
Avg
Python
Go
Ruby
PHP
Java
JS
Carptriever-1
48.59
55.98
43.18
56.06
45.62
46.04
44.66
Contriever
37
45.43
36.08
48.07
25.59
32.89
31.44
Acknowledgements
This work would not have been possible without the compute support of
Stability AI
.
Thank you to Louis Castricato for research guidance and Reshinth Adithyan for creating the CodeSearchNet evaluation script.
Citations
@misc{izacard2021contriever,
title={Unsupervised Dense Information Retrieval with Contrastive Learning},
author={Gautier Izacard and Mathilde Caron and Lucas Hosseini and Sebastian Riedel and Piotr Bojanowski and Armand Joulin and Edouard Grave},
year={2021},
url = {https://arxiv.org/abs/2112.09118},
doi = {10.48550/ARXIV.2112.09118},
}
@article{pile,
title={The {P}ile: An 800GB Dataset of Diverse Text for Language Modeling},
author={Gao, Leo and Biderman, Stella and Black, Sid and Golding, Laurence and Hoppe, Travis and Foster, Charles and Phang, Jason and He, Horace and Thite, Anish and Nabeshima, Noa and Presser, Shawn and Leahy, Connor},
journal={arXiv preprint arXiv:2101.00027},
year={2020}
}
Runs of CarperAI carptriever-1 on huggingface.co
77
Total runs
0
24-hour runs
1
3-day runs
3
7-day runs
21
30-day runs
More Information About carptriever-1 huggingface.co Model
carptriever-1 huggingface.co is an AI model on huggingface.co that provides carptriever-1's model effect (), which can be used instantly with this CarperAI carptriever-1 model. huggingface.co supports a free trial of the carptriever-1 model, and also provides paid use of the carptriever-1. Support call carptriever-1 model through api, including Node.js, Python, http.
carptriever-1 huggingface.co is an online trial and call api platform, which integrates carptriever-1's modeling effects, including api services, and provides a free online trial of carptriever-1, you can try carptriever-1 online for free by clicking the link below.
CarperAI carptriever-1 online free url in huggingface.co:
carptriever-1 is an open source model from GitHub that offers a free installation service, and any user can find carptriever-1 on GitHub to install. At the same time, huggingface.co provides the effect of carptriever-1 install, users can directly use carptriever-1 installed effect in huggingface.co for debugging and trial. It also supports api for free installation.