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

FEA & DOC: add encoding for reading atomic files and fix doc. #966

Merged
merged 4 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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: 2 additions & 0 deletions docs/source/user_guide/config/environment_settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Environment settings are designed to set basic parameters of running environment
- ``seed (int)`` : Random seed. Defaults to ``2020``.
- ``state (str)`` : Logging level. Defaults to ``'INFO'``.
Range in ``['INFO', 'DEBUG', 'WARNING', 'ERROR', 'CRITICAL']``.
- ``encoding (str)``: Encoding to use for reading atomic files. Defaults to ``'utf-8'``.
The available encoding can be found in `here <https://docs.python.org/3/library/codecs.html#standard-encodings>`__.
- ``reproducibility (bool)`` : If True, the tool will use deterministic
convolution algorithms, which makes the result reproducible. If False,
the tool will benchmark multiple convolution algorithms and select the fastest one,
Expand Down
9 changes: 6 additions & 3 deletions recbole/data/dataset/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,8 @@ def _load_feat(self, filepath, source):
columns = []
usecols = []
dtype = {}
with open(filepath, 'r') as f:
encoding = self.config['encoding']
with open(filepath, 'r', encoding=encoding) as f:
head = f.readline()[:-1]
for field_type in head.split(field_separator):
field, ftype = field_type.split(':')
Expand All @@ -429,7 +430,9 @@ def _load_feat(self, filepath, source):
self.logger.warning(f'No columns has been loaded from [{source}]')
return None

df = pd.read_csv(filepath, delimiter=self.config['field_separator'], usecols=usecols, dtype=dtype)
df = pd.read_csv(
filepath, delimiter=self.config['field_separator'], usecols=usecols, dtype=dtype, encoding=encoding
)
df.columns = columns

seq_separator = self.config['seq_separator']
Expand Down Expand Up @@ -484,7 +487,7 @@ def _user_item_feat_preparation(self):
if self.item_feat is not None:
new_item_df = pd.DataFrame({self.iid_field: np.arange(self.item_num)})
self.item_feat = pd.merge(new_item_df, self.item_feat, on=self.iid_field, how='left')
self.logger.debug(set_color('ordering item features by user id.', 'green'))
self.logger.debug(set_color('ordering item features by item id.', 'green'))

def _preload_weight_matrix(self):
"""Transfer preload weight features into :class:`numpy.ndarray` with shape ``[id_token_length]``
Expand Down