Skip to content

Sourcery refactored master branch#1

Open
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master
Open

Sourcery refactored master branch#1
sourcery-ai[bot] wants to merge 1 commit intomasterfrom
sourcery/master

Conversation

@sourcery-ai
Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot commented Aug 30, 2023

Branch master refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the master branch, then run:

git fetch origin sourcery/master
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

@sourcery-ai sourcery-ai Bot requested a review from Let0Pda August 30, 2023 09:55
Copy link
Copy Markdown
Author

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sourcery timed out performing refactorings.

Due to GitHub API limits, only the first 60 comments can be shown.

for line in reader:
if sys.version_info[0] == 2:
line = list(unicode(cell, 'utf-8') for cell in line)
line = [unicode(cell, 'utf-8') for cell in line]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function DataProcessor._read_tsv refactored with the following changes:

"""See base class."""
logger.info("LOOKING AT {}".format(
os.path.join(data_dir, "train.tsv")))
logger.info(f'LOOKING AT {os.path.join(data_dir, "train.tsv")}')
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MrpcProcessor.get_train_examples refactored with the following changes:

Comment on lines -134 to +133
guid = "%s-%s" % (set_type, i)
guid = f"{set_type}-{i}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MrpcProcessor._create_examples refactored with the following changes:

Comment on lines -167 to +166
guid = "%s-%s" % (set_type, line[0])
guid = f"{set_type}-{line[0]}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MnliProcessor._create_examples refactored with the following changes:

Comment on lines -207 to +206
guid = "%s-%s" % (set_type, i)
guid = f"{set_type}-{i}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ColaProcessor._create_examples refactored with the following changes:

Comment on lines -196 to +193
guid = "%s-%s" % (set_type, line[0])
guid = f"{set_type}-{line[0]}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function MnliProcessor._create_examples refactored with the following changes:

Comment on lines -237 to +234
guid = "%s-%s" % (set_type, i)
guid = f"{set_type}-{i}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ColaProcessor._create_examples refactored with the following changes:

Comment on lines -270 to +267
guid = "%s-%s" % (set_type, i)
guid = f"{set_type}-{i}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function Sst2Processor._create_examples refactored with the following changes:

Comment on lines -303 to +300
guid = "%s-%s" % (set_type, line[0])
guid = f"{set_type}-{line[0]}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function StsbProcessor._create_examples refactored with the following changes:

Comment on lines -337 to +334
guid = "%s-%s" % (set_type, line[0])
guid = f"{set_type}-{line[0]}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QqpProcessor._create_examples refactored with the following changes:

Comment on lines -374 to +371
guid = "%s-%s" % (set_type, line[0])
guid = f"{set_type}-{line[0]}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function QnliProcessor._create_examples refactored with the following changes:

Comment on lines -408 to +405
guid = "%s-%s" % (set_type, line[0])
guid = f"{set_type}-{line[0]}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function RteProcessor._create_examples refactored with the following changes:

Comment on lines -442 to +439
guid = "%s-%s" % (set_type, line[0])
guid = f"{set_type}-{line[0]}"
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function WnliProcessor._create_examples refactored with the following changes:

Comment on lines -474 to +472
else:
# Account for [CLS] and [SEP] with "- 2"
if len(tokens_a) > max_seq_length - 2:
tokens_a = tokens_a[:(max_seq_length - 2)]
elif len(tokens_a) > max_seq_length - 2:
tokens_a = tokens_a[:(max_seq_length - 2)]
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function convert_examples_to_features refactored with the following changes:

This removes the following comments ( why? ):

# Account for [CLS] and [SEP] with "- 2"

Comment on lines -84 to +90
print("Converting TensorFlow checkpoint from {}".format(tf_path))
print(f"Converting TensorFlow checkpoint from {tf_path}")
# Load weights from TF model
init_vars = tf.train.list_variables(tf_path)
names = []
arrays = []
for name, shape in init_vars:
print("Loading TF weight {} with shape {}".format(name, shape))
print(f"Loading TF weight {name} with shape {shape}")
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function load_tf_weights_in_bert refactored with the following changes:

Comment on lines -1019 to +1020
if masked_lm_labels is not None and next_sentence_label is not None:
loss_fct = CrossEntropyLoss(ignore_index=-1)
masked_lm_loss = loss_fct(
prediction_scores.view(-1, self.config.vocab_size),
masked_lm_labels.view(-1))
next_sentence_loss = loss_fct(seq_relationship_score.view(-1, 2),
next_sentence_label.view(-1))
#print("loss is {} {}".format(masked_lm_loss, next_sentence_loss))
total_loss = masked_lm_loss + next_sentence_loss
# if log:
# self.log_summary_writer(logs={'train_loss': total_loss.item()})
return total_loss
else:
if masked_lm_labels is None or next_sentence_label is None:
return prediction_scores, seq_relationship_score
loss_fct = CrossEntropyLoss(ignore_index=-1)
masked_lm_loss = loss_fct(
prediction_scores.view(-1, self.config.vocab_size),
masked_lm_labels.view(-1))
next_sentence_loss = loss_fct(seq_relationship_score.view(-1, 2),
next_sentence_label.view(-1))
return masked_lm_loss + next_sentence_loss
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BertForPreTraining.forward refactored with the following changes:

This removes the following comments ( why? ):

#                self.log_summary_writer(logs={'train_loss': total_loss.item()})
#            if log:
#print("loss is {} {}".format(masked_lm_loss, next_sentence_loss))

Comment on lines -1092 to +1083
masked_lm_loss = loss_fct(
return loss_fct(
prediction_scores.view(-1, self.config.vocab_size),
masked_lm_labels.view(-1))
return masked_lm_loss
masked_lm_labels.view(-1),
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BertForMaskedLM.forward refactored with the following changes:

Comment on lines -1155 to +1148
if next_sentence_label is not None:
loss_fct = CrossEntropyLoss(ignore_index=-1)
next_sentence_loss = loss_fct(seq_relationship_score.view(-1, 2),
next_sentence_label.view(-1))
return next_sentence_loss
else:
if next_sentence_label is None:
return seq_relationship_score
loss_fct = CrossEntropyLoss(ignore_index=-1)
return loss_fct(
seq_relationship_score.view(-1, 2), next_sentence_label.view(-1)
)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BertForNextSentencePrediction.forward refactored with the following changes:

Comment on lines -1225 to +1212
loss = loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
return loss
return loss_fct(logits.view(-1, self.num_labels), labels.view(-1))
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BertForSequenceClassification.forward refactored with the following changes:

Comment on lines -1294 to +1283
if labels is not None:
loss_fct = CrossEntropyLoss()
loss = loss_fct(reshaped_logits, labels)
return loss
else:
if labels is None:
return reshaped_logits
loss_fct = CrossEntropyLoss()
return loss_fct(reshaped_logits, labels)
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function BertForMultipleChoice.forward refactored with the following changes:

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

Successfully merging this pull request may close these issues.

0 participants