Skip to content

Fix typos in LLARA #1363

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion research/LLARA/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ run.py \
--num_train_epochs 1 \
--per_device_train_batch_size 1 \
--dataloader_drop_last True \
--normlized True \
--normalized True \
--temperature 0.01 \
--query_max_len 64 \
--passage_max_len 160 \
Expand Down
2 changes: 1 addition & 1 deletion research/LLARA/finetune/arguments.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,6 @@ class RetrieverTrainingArguments(TrainingArguments):
temperature: Optional[float] = field(default=0.02)
fix_position_embedding: bool = field(default=False, metadata={"help": "Freeze the parameters of position embeddings"})
sentence_pooling_method: str = field(default='cls', metadata={"help": "the pooling method, should be cls or mean"})
normlized: bool = field(default=True)
normalized: bool = field(default=True)
sub_batch_size: int = field(default=None)
cache_chunk_size: int = field(default=-1, metadata={"help": "用于缓存每一步的执行."})
12 changes: 6 additions & 6 deletions research/LLARA/finetune/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class BiEncoderModel(nn.Module):
def __init__(self,
model: AutoModel = None,
tokenizer: AutoTokenizer = None,
normlized: bool = False,
normalized: bool = False,
negatives_cross_device: bool = False,
temperature: float = 1.0,
sub_batch_size: int = -1
Expand All @@ -38,9 +38,9 @@ def __init__(self,
self.tokenizer = tokenizer
self.cross_entropy = nn.CrossEntropyLoss(reduction='mean')

self.normlized = normlized
self.normalized = normalized
self.temperature = temperature
if not normlized:
if not normalized:
self.temperature = 1.0
logger.info("reset temperature = 1.0 due to using inner product to compute similarity")

Expand Down Expand Up @@ -80,14 +80,14 @@ def encode(self, features):
p_reps = torch.mean(p_reps, dim=1)
all_p_reps.append(p_reps)
all_p_reps = torch.cat(all_p_reps, 0).contiguous()
if self.normlized:
if self.normalized:
all_p_reps = torch.nn.functional.normalize(all_p_reps, dim=-1)
return all_p_reps.contiguous()
else:
psg_out = self.model(**features, return_dict=True, output_hidden_states=True)
p_reps = psg_out.hidden_states[-1][:, -8:, :]
p_reps = torch.mean(p_reps, dim=1)
if self.normlized:
if self.normalized:
p_reps = torch.nn.functional.normalize(p_reps, dim=-1)
return p_reps.contiguous()
else:
Expand All @@ -99,7 +99,7 @@ def encode(self, features):
p_reps = torch.mean(p_reps, dim=1)
all_p_reps.append(p_reps)
all_p_reps = torch.cat(all_p_reps, 0).contiguous()
if self.normlized:
if self.normalized:
all_p_reps = torch.nn.functional.normalize(all_p_reps, dim=-1)
return all_p_reps.contiguous()

Expand Down
2 changes: 1 addition & 1 deletion research/LLARA/finetune/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def main():

model = BiEncoderModel(model=base_model,
tokenizer=tokenizer,
normlized=training_args.normlized,
normalized=training_args.normalized,
negatives_cross_device=training_args.negatives_cross_device,
temperature=training_args.temperature,
sub_batch_size=training_args.sub_batch_size)
Expand Down
2 changes: 1 addition & 1 deletion research/LLARA/finetune/trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def _save(self, output_dir: Optional[str] = None, state_dict=None):
# if self.is_world_process_zero():
# save_ckpt_for_sentence_transformers(output_dir,
# pooling_mode=self.args.sentence_pooling_method,
# normlized=self.args.normlized)
# normalized=self.args.normalized)

def compute_loss(self, model, inputs, return_outputs=False):
"""
Expand Down