Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to install? #2

Open
stephenleo opened this issue Apr 29, 2022 · 5 comments
Open

How to install? #2

stephenleo opened this issue Apr 29, 2022 · 5 comments

Comments

@stephenleo
Copy link

Could you pls share how to install diffcse? I tried the below

pip install simcse
git clone [email protected]:voidism/DiffCSE.git
cd transformers-4.2.1
pip install .

then running

from diffcse import DiffCSE

results in ModuleNotFoundError

Thanks!

@voidism
Copy link
Owner

voidism commented Apr 29, 2022

You need to be in the DiffCSE folder to run from diffcse import DiffCSE.
If you want to import diffcse from anywhere, you can run pip install . in the DiffCSE folder to install DiffCSE globally.

@stephenleo
Copy link
Author

Thanks! was able to import and run on STS-B dataset. However, loading the model throws this warning. Is it expected?

from DiffCSE.diffcse import DiffCSE
model = DiffCSE('voidism/diffcse-roberta-base-sts')
Some weights of RobertaModel were not initialized from the model checkpoint at voidism/diffcse-roberta-base-sts and are newly initialized: ['roberta.pooler.dense.weight', 'roberta.pooler.dense.bias']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.

@voidism
Copy link
Owner

voidism commented May 4, 2022

Hi! I just changed the code in diffcse/tool.py by f724b2c to make it always use the [CLS] vector before the pooler. In the experiment that works better. By doing so, we are not going to use ['roberta.pooler.dense.weight', 'roberta.pooler.dense.bias'] so it's ok to ignore that warning.

@JhonDan1999
Copy link

JhonDan1999 commented Oct 1, 2023

I am having the issue when I tried to use the model through huggingface like this:

Screenshot 2023-10-01 at 11 20 03 AM

it gave me this long warning:

Some weights of the model checkpoint at voidism/diffcse-roberta-base-sts were not used when initializing RobertaModel:
then it shows all the layers like this:

aux_bert.encoder.layer.7.output.dense.bias', 'aux_bert.encoder.layer.8.intermediate.dense.bias', 'aux_bert.encoder.layer.10.intermediate.dense.bias', 'aux_bert.encoder.layer.4.intermediate.dense.bias', 'aux_bert.encoder.layer.9.intermediate.dense.weight', 'aux_bert.encoder.layer.11.attention.self.query.weight', 'generator.lm_head.dense.bias', 'generator.roberta.encoder.layer.5.attention.output.dense.weight', 'aux_bert.encoder.layer.7.output.LayerNorm.bias', 'generator.roberta.encoder.layer.0.attention.output.dense.bias', 'aux_bert.encoder.layer.6.output.LayerNorm.weight', 'aux_bert.encoder.layer.4.output.dense.weight', 'aux_bert.encoder.layer.2.attention.output.LayerNorm.bias', 'generator.roberta.encoder.layer.5.intermediate.dense.bias', 'generator.roberta.encoder.layer.2.attention.self.query.weight', 'aux_bert.encoder.layer.9.intermediate.dense.bias', 'generator.roberta.encoder.layer.4.attention.self.key.weight', 'generator.roberta.encoder.layer.4.attention.output.dense.weight', 'generator.roberta.encoder.layer.1.output.LayerNorm.bias', 'generator.roberta.embeddings.position_ids', 'generator.roberta.encoder.layer.3.intermediate.dense.bias', 'aux_bert.encoder.layer.1.attention.self.key.bias', 'aux_bert.encoder.layer.2.output.dense.weight', 'generator.roberta.encoder.layer.2.intermediate.dense.bias', 'aux_bert.encoder.layer.8.attention.self.value.weight', 'aux_bert.encoder.layer.10.attention.self.key.bias', 'aux_bert.encoder.layer.9.attention.self.value.weight', 'generator.lm_head.decoder.bias', 'generator.roberta.encoder.layer.3.attention.output.dense.weight', 'aux_bert.encoder.layer.3.output.dense.bias', 'aux_bert.encoder.layer.0.output.LayerNorm.weight', 'aux_bert.encoder.layer.1.attention.output.LayerNorm.bias', 'generator.roberta.encoder.layer.2.attention.self.key.weight', 'generator.roberta.encoder.layer.0.output.dense.weight', 'aux_bert.encoder.layer.5.attention.self.key.weight', 'aux_bert.encoder.layer.11.intermediate.dense.weight', 'aux_bert.encoder.layer.6.attention.output.dense.weight']
- This IS expected if you are initializing RobertaModel from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing RobertaModel from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Some weights of RobertaModel were not initialized from the model checkpoint at voidism/diffcse-roberta-base-sts and are newly initialized: ['roberta.pooler.dense.bias', 'roberta.pooler.dense.weight'

at the end it give this:
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference. Asking to truncate to max_length but no maximum length is provided and the model has no predefined maximum length. Default to no truncation.

I am not sure if I can ignore this and use the model please confirm to me

@voidism
Copy link
Owner

voidism commented Oct 1, 2023

Hi @JhonDan1999

The warning is caused by loading our DiffCSE model (encoder-decoder arch) into the RoBERTa model (encoder-only arch).
So the decoder weights (in the names starting withaux_bert.) are not used when initializing RobertaModel.

If you only want to extract sentence embeddings without training, it should be fine, as you don't need the decoder to extract.

For the second warning, if you're using RoBERTa, just make sure that your sentence length is not longer than 514 (including BOS/EOS), then it should be fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants