-
Notifications
You must be signed in to change notification settings - Fork 0
GH-560: Add encoding='utf-8' to fix "UnicodeDecodeError" (Sourcery refactored) #3
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
base: sourcery/master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,14 +22,13 @@ def encode(self, labels): | |
| if type(labels) == list: | ||
| return [self.encode(label) for label in labels] | ||
| label = labels # label is a string | ||
| if label not in self.label2index: | ||
| index = self.vocab_size | ||
| self.label2index[label] = index | ||
| self.index2label[index] = label | ||
| self.vocab_size += 1 | ||
| return index | ||
| else: | ||
| if label in self.label2index: | ||
| return self.label2index[label] | ||
| index = self.vocab_size | ||
| self.label2index[label] = index | ||
| self.index2label[index] = label | ||
| self.vocab_size += 1 | ||
| return index | ||
|
|
||
|
|
||
| class UITABSAHotel: | ||
|
|
@@ -41,7 +40,7 @@ def __init__(self, training="aspect"): | |
| train_file = join(DATASETS_FOLDER, UITABSAHotel.NAME, "Train_Hotel.txt") | ||
| dev_file = join(DATASETS_FOLDER, UITABSAHotel.NAME, "Dev_Hotel.txt") | ||
| test_file = join(DATASETS_FOLDER, UITABSAHotel.NAME, "Test_Hotel.txt") | ||
| print("Currently training: %s (aspect or polarity)" % training) | ||
| print(f"Currently training: {training} (aspect or polarity)") | ||
|
Comment on lines
+44
to
+43
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| self.training = training # aspect or polarity | ||
| self.label_encoder = LabelEncoder() | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -22,14 +22,13 @@ def encode(self, labels): | |
| if type(labels) == list: | ||
| return [self.encode(label) for label in labels] | ||
| label = labels # label is a string | ||
| if label not in self.label2index: | ||
| index = self.vocab_size | ||
| self.label2index[label] = index | ||
| self.index2label[index] = label | ||
| self.vocab_size += 1 | ||
| return index | ||
| else: | ||
| if label in self.label2index: | ||
| return self.label2index[label] | ||
| index = self.vocab_size | ||
| self.label2index[label] = index | ||
| self.index2label[index] = label | ||
| self.vocab_size += 1 | ||
| return index | ||
|
Comment on lines
+25
to
+31
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
|
|
||
| class UITABSARestaurant: | ||
|
|
@@ -41,7 +40,7 @@ def __init__(self, training="aspect"): | |
| train_file = join(DATASETS_FOLDER, UITABSARestaurant.NAME, "Train.txt") | ||
| dev_file = join(DATASETS_FOLDER, UITABSARestaurant.NAME, "Dev.txt") | ||
| test_file = join(DATASETS_FOLDER, UITABSARestaurant.NAME, "Test.txt") | ||
| print("Currently training: %s (aspect or polarity)" % training) | ||
| print(f"Currently training: {training} (aspect or polarity)") | ||
|
Comment on lines
+44
to
+43
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Function
|
||
|
|
||
| self.training = training # aspect or polarity | ||
| self.label_encoder = LabelEncoder() | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function
LabelEncoder.encoderefactored with the following changes:swap-if-else-branches)remove-unnecessary-else)