Instructions to use modularStarEncoder/ModularStarEncoder with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use modularStarEncoder/ModularStarEncoder with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="modularStarEncoder/ModularStarEncoder", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("modularStarEncoder/ModularStarEncoder", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files12345678919 unmodified lines2930313233343536373839404142434445464748495051522 unmodified lines55565758596061626364---library_name: transformersdatasets:- bigcode/the-stack-v2license: bigcode-openrail-m---# Model Card for Model ID19 unmodified linesfrom transformers import AutoTokenizer#import the modelmodel = AutoModel.from_pretrained("andreagurioli1995/ModularStarEncoder-finetuned", trust_remote_code=True)#import the tokenizertokenizer = AutoTokenizer.from_pretrained("andreagurioli1995/ModularStarEncoder-finetuned")language = "yourlanguagelowercased"#instruction in case of code embedding in a code languageinstruction_code = f"Represent this {language} code snippet for retrieval:"#instruction in case of code embedding in Englishinstruction_natural_language = "Represent this code description for retrieving supporting snippets of code:"code_snippet = "your code to embed here"#You should follow this pattern to embed a snippet of code or natural language queriessentence = f"{tokenizer.sep_token}{instruction_code}{tokenizer.sep_token}{code_snippet)}{tokenizer.cls_token}"#Tokenizing your sentencetokenized_sensence = tokenizer(sentence, return_tensors="pt",truncation=True, max_length=2048)2 unmodified linesembedded_sentence = model(**sentence)```You will get as an output three elements:- projected_pooled_normalized: a list of the projected, pooled, and normalized embeddings from the five exit points;- raw_hidden_states: raw representation from all the hidden states of the model, without pooling, normalization, and projection- attentions: attention scores from the encoder### Model Description12345678919 unmodified lines29303132333435363738394041424344452 unmodified lines48495051525354555657585960---library_name: transformersdatasets:- bigcode/the-stack-v2license: bigcode-openrail-m---# Model Card for Model ID19 unmodified linesfrom transformers import AutoTokenizer#import the modelmodel = AutoModel.from_pretrained("andreagurioli1995/ModularStarEncoder", trust_remote_code=True)#import the tokenizertokenizer = AutoTokenizer.from_pretrained("andreagurioli1995/ModularStarEncoder")code_snippet = "your code to embed here"#You should follow this pattern to embed a snippet of codesentence = f"{tokenizer.sep_token}{code_snippet}{tokenizer.cls_token}#Tokenizing your sentencetokenized_sensence = tokenizer(sentence, return_tensors="pt",truncation=True, max_length=2048)2 unmodified linesembedded_sentence = model(**sentence)```You will get as an output six elements:- last_hidden_state: the representation of the last hidden state from the model;- hidden_states: raw representation from all the hidden states of the model, without pooling, normalization, and projection- loss: loss value if a ground truth is given (None if used in inference)- prediction_logits: prediction scores from masked language modeling head- seq_relationship_scores: prediction scores of in-context loss (concatenate multiple samples with the separator token if you want a meaningful score)- attentions: attention scores from the encoder### Model Description
README.md+16-20