Run this model with HF Jobs
Run Lazyhope/python-clone-detection on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.
Paste one of these prompts into your coding agent:
Fine-tune on my dataset
Use HF Jobs to fine-tune https://huggingface.co/Lazyhope/python-clone-detection. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.
Run batch inference
Use HF Jobs to run batch inference with https://huggingface.co/Lazyhope/python-clone-detection on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.
Instructions to use Lazyhope/python-clone-detection with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Lazyhope/python-clone-detection with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="Lazyhope/python-clone-detection", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModel tokenizer = AutoTokenizer.from_pretrained("Lazyhope/python-clone-detection", trust_remote_code=True) model = AutoModel.from_pretrained("Lazyhope/python-clone-detection", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
Upload model
Browse filesFiles changed (3)
- CloneDetectionModel.pyAdded+96
- config.json+5-2
- pytorch_model.bin+2-2
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596"""Original work:https://github.com/sangHa0411/CloneDetection/blob/main/models/codebert.py#L169
Copyright (c) 2022 Sangha Park(sangha110495), Young Jin Ahn(snoop2head)
All credits to the original authors."""import torch.nn as nnfrom transformers import ( RobertaPreTrainedModel, RobertaModel,)from transformers.modeling_outputs import SequenceClassifierOutput
class CloneDetectionModel(RobertaPreTrainedModel): _keys_to_ignore_on_load_missing = [r"position_ids"]
def __init__(self, config): super().__init__(config) self.num_labels = config.num_labels self.config = config
self.roberta = RobertaModel(config, add_pooling_layer=False) self.net = nn.Sequential( nn.Dropout(config.hidden_dropout_prob), nn.Linear(config.hidden_size, config.hidden_size), nn.ReLU(), ) self.classifier = nn.Linear(config.hidden_size * 4, config.num_labels)
def forward( self, input_ids=None, attention_mask=None, token_type_ids=None, position_ids=None, head_mask=None, inputs_embeds=None, labels=None, output_attentions=None, output_hidden_states=None, return_dict=None, ):
return_dict = ( return_dict if return_dict is not None else self.config.use_return_dict )
outputs = self.roberta( input_ids, attention_mask=attention_mask, token_type_ids=token_type_ids, position_ids=position_ids, head_mask=head_mask, inputs_embeds=inputs_embeds, output_attentions=output_attentions, output_hidden_states=output_hidden_states, return_dict=return_dict, )
hidden_states = outputs[0] batch_size, _, hidden_size = hidden_states.shape
# CLS code1 SEP SEP code2 SEP cls_flag = input_ids == self.config.tokenizer_cls_token_id # cls token sep_flag = input_ids == self.config.tokenizer_sep_token_id # sep token
special_token_states = hidden_states[cls_flag + sep_flag].view( batch_size, -1, hidden_size ) # (batch_size, 4, hidden_size) special_hidden_states = self.net( special_token_states ) # (batch_size, 4, hidden_size)
pooled_output = special_hidden_states.view( batch_size, -1 ) # (batch_size, hidden_size * 4) logits = self.classifier(pooled_output) # (batch_size, num_labels)
loss = None if labels is not None: loss_fct = nn.CrossEntropyLoss() loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
if not return_dict: output = (logits,) + outputs[2:] return ((loss,) + output) if loss is not None else output
return SequenceClassifierOutput( loss=loss, logits=logits, hidden_states=outputs.hidden_states, attentions=outputs.attentions, )123456789{"_name_or_path": "microsoft/graphcodebert-base","architectures": ["RobertaRBERT"],"attention_probs_dropout_prob": 0.1,"bos_token_id": 0,"classifier_dropout": null,"dropout_rate": 0.1,123456789101112{"_name_or_path": "./checkpoint","architectures": ["CloneDetectionModel"],"attention_probs_dropout_prob": 0.1,"auto_map": {"AutoModel": "CloneDetectionModel.CloneDetectionModel"},"bos_token_id": 0,"classifier_dropout": null,"dropout_rate": 0.1,
123version https://git-lfs.github.com/spec/v1oid sha256:ee6809a890981926df5d49e47747fc9912290459d9d678e7f89a49ceb133200dsize 498680501123version https://git-lfs.github.com/spec/v1oid sha256:cd61ea43ac55f9dcb691449f3489fbc90638a96a958289b24c7abf6306642f02size 498675949
CloneDetectionModel.pyAdded+96
config.json+5-2
pytorch_model.bin+2-2