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

fix(xlnet): Set training mode to False and set dropout to zero #47

Closed
wants to merge 3 commits into from
Closed
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
4 changes: 3 additions & 1 deletion server/embedding_as_service/text/xlnet/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,9 @@ def _model_single_input(self, text: Union[str, List[str]], is_tokenized: bool
def load_model(self, model: str, model_path: str, max_seq_length: int):
model_path = os.path.join(model_path, next(os.walk(model_path))[1][0])
self.xlnet_config = xlnet.XLNetConfig(json_path=os.path.join(model_path, Embeddings.mode_config_path))
self.run_config = xlnet.create_run_config(is_training=True, is_finetune=True, FLAGS=Flags)
self.xlnet_config.dropout = self.xlnet_config.dropatt = 0.0
self.run_config = xlnet.create_run_config(is_training=False, is_finetune=False, FLAGS=Flags)
self.run_config.dropout = self.run_config.dropatt = 0.0
self.load_tokenizer(model_path)
self.max_seq_length = max_seq_length
self.model_name = model
Expand Down
9 changes: 6 additions & 3 deletions server/embedding_as_service/text/xlnet/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
class Flags:

# Model
model_config_path: str = None # Model config path
dropout: float = 0.1 # Dropout rate
Expand All @@ -11,7 +10,7 @@ class Flags:

# Parameter initialization
init: str = "normal"
init_std: float = 0.2 # Initialization std when init is normal.
init_std: float = 0.2 # Initialization std when init is normal.
init_range: float = 0.1 # Initialization std when init is uniform.

# I/O paths
Expand Down Expand Up @@ -44,13 +43,17 @@ class Flags:
# Low layer: lr[l-1] = lr[l] * lr_layer_decay_rate.

min_lr_ratio: float = 0.0 # min lr ratio for cos decay.
clip: float = 1.0 # Gradient clipping
clip: float = 1.0 # Gradient clipping
max_save: int = 0 # Max number of checkpoints to save. Use 0 to save all.
save_steps: int = None # Save the model for every save_steps. If None, not to save any model.
train_batch_size: int = 8 # Batch size for training
weight_decay: float = 0.00 # Weight decay rate
adam_epsilon: float = 1e-8 # Adam epsilon
decay_method: str = "poly" # poly or cos
mem_len: int = 0 # Number of steps to cache
same_length: bool = False # Same length attention
reuse_len: int = 0 # How many tokens to be reused in the next batch.
bi_data: bool = False # Use bidirectional data streams, i.e., forward & backward.

# evaluation
do_eval: bool = False # whether to do eval
Expand Down