Skip to content

Commit fbaef08

Browse files
No public description
PiperOrigin-RevId: 590661941
1 parent 505f9bf commit fbaef08

File tree

8 files changed

+60
-38
lines changed

8 files changed

+60
-38
lines changed

docs/nlp/customize_encoder.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
"source": [
7171
"## Learning objectives\n",
7272
"\n",
73-
"The [TensorFlow Models NLP library](https://github.com/tensorflow/models/tree/master/official/nlp/modeling) is a collection of tools for building and training modern high-performance natural language models.\n",
73+
"The [TensorFlow Models NLP library](https://github.com/tensorflow/models/tree/master/official/nlp/modeling) is a collection of tools for building and training modern high performance natural language models.\n",
7474
"\n",
7575
"The `tfm.nlp.networks.EncoderScaffold` is the core of this library, and lots of new network architectures are proposed to improve the encoder. In this Colab notebook, we will learn how to customize the encoder to employ new network architectures."
7676
]
@@ -151,7 +151,7 @@
151151
"source": [
152152
"## Canonical BERT encoder\n",
153153
"\n",
154-
"Before learning how to customize the encoder, let's first create a canonical BERT encoder and use it to instantiate a `bert_classifier.BertClassifier` for the classification task."
154+
"Before learning how to customize the encoder, let's firstly create a canonical BERT enoder and use it to instantiate a `bert_classifier.BertClassifier` for classification task."
155155
]
156156
},
157157
{
@@ -256,9 +256,9 @@
256256
"source": [
257257
"#### Without Customization\n",
258258
"\n",
259-
"Without any customization, `networks.EncoderScaffold` behaves the same as the canonical `networks.BertEncoder`.\n",
259+
"Without any customization, `networks.EncoderScaffold` behaves the same the canonical `networks.BertEncoder`.\n",
260260
"\n",
261-
"As shown in the following example, `networks.EncoderScaffold` can load `networks.BertEncoder`'s weights and output are the same values:"
261+
"As shown in the following example, `networks.EncoderScaffold` can load `networks.BertEncoder`'s weights and output the same values:"
262262
]
263263
},
264264
{
@@ -564,7 +564,7 @@
564564
"id": "MeidDfhlHKSO"
565565
},
566566
"source": [
567-
"Inspecting the `albert_encoder`, we see it stacks the same `Transformer` layer multiple times (note the loop-back on the \"Transformer\" block below."
567+
"Inspecting the `albert_encoder`, we see it stacks the same `Transformer` layer multiple times (note the loop-back on the \"Transformer\" block below.."
568568
]
569569
},
570570
{

official/projects/text_classification_example/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class ClassificationDataLoader(data_loader.DataLoader):
4444
...
4545
```
4646

47-
Overall, loader will translate the tf.Example to appropriate format for model to
47+
Overall, loader will translate the tf.Example to approiate format for model to
4848
consume. Then in Task.build_inputs, link the dataset like
4949

5050
```python
@@ -88,7 +88,7 @@ task_config = classification_example.ClassificationExampleConfig()
8888
task = classification_example.ClassificationExampleTask(task_config)
8989
```
9090

91-
TIPs: You can also check the [unittest](https://github.com/tensorflow/models/blob/master/official/projects/text_classification_example/classification_example_test.py)
91+
TIPs: You can also check the [unittest](https://github.com/tensorflow/models/blob/master/official/nlp/projects/example/classification_example_test.py)
9292
for better understanding.
9393

9494
### Finetune

official/recommendation/movielens.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989

9090

9191
def _download_and_clean(dataset, data_dir):
92-
"""Download the MovieLens dataset in a standard format.
92+
"""Download MovieLens dataset in a standard format.
9393
9494
This function downloads the specified MovieLens format and coerces it into a
9595
standard format. The only difference between the ml-1m and ml-20m datasets
@@ -148,10 +148,10 @@ def _transform_csv(input_path, output_path, names, skip_first, separator=","):
148148
149149
Args:
150150
input_path: The path of the raw csv.
151-
output_path: The location of the cleaned csv file.
152-
names: The names of the csv columns.
153-
skip_first: Boolean indicating whether the first line of the raw csv should be skipped.
154-
separator: A character used in raw csv to separate fields.
151+
output_path: The path of the cleaned csv.
152+
names: The csv column names.
153+
skip_first: Boolean of whether to skip the first line of the raw csv.
154+
separator: Character used to separate fields in the raw csv.
155155
"""
156156
if six.PY2:
157157
names = [six.ensure_text(n, "utf-8") for n in names]
@@ -179,17 +179,17 @@ def _regularize_1m_dataset(temp_dir):
179179
ratings.dat
180180
The file has no header row, and each line is in the following format:
181181
UserID::MovieID::Rating::Timestamp
182-
- UserIDs range between 1 and 6040
183-
- MovieIDs can range between 1 and 3952
182+
- UserIDs range from 1 and 6040
183+
- MovieIDs range from 1 and 3952
184184
- Ratings are made on a 5-star scale (whole-star ratings only)
185-
- Timestamp is represented in seconds since midnight. Coordinated Universal
185+
- Timestamp is represented in seconds since midnight Coordinated Universal
186186
Time (UTC) of January 1, 1970.
187187
- Each user has at least 20 ratings
188188
189189
movies.dat
190190
Each line has the following format:
191191
MovieID::Title::Genres
192-
- MovieIDs can range between 1 and 3952
192+
- MovieIDs range from 1 and 3952
193193
"""
194194
working_dir = os.path.join(temp_dir, ML_1M)
195195

@@ -223,7 +223,7 @@ def _regularize_20m_dataset(temp_dir):
223223
movies.csv
224224
Each line has the following format:
225225
MovieID,Title,Genres
226-
- MovieIDs can range between 1 and 3952
226+
- MovieIDs range from 1 and 3952
227227
"""
228228
working_dir = os.path.join(temp_dir, ML_20M)
229229

@@ -265,7 +265,7 @@ def csv_to_joint_dataframe(data_dir, dataset):
265265

266266

267267
def integerize_genres(dataframe):
268-
"""Replace the genre string with a binary vector.
268+
"""Replace genre string with a binary vector.
269269
270270
Args:
271271
dataframe: a pandas dataframe of movie data.
@@ -308,7 +308,7 @@ def define_data_download_flags():
308308

309309

310310
def main(_):
311-
"""Download and extract the data from the GroupLens website."""
311+
"""Download and extract the data from GroupLens website."""
312312
download(flags.FLAGS.dataset, flags.FLAGS.data_dir)
313313

314314

official/recommendation/ncf_common.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def define_ncf_flags():
191191
default=None,
192192
help=flags_core.help_wrap(
193193
"The batch size used for evaluation. This should generally be larger"
194-
"than the training batch size, as the lack of back propagation during"
194+
"than the training batch size as the lack of back propagation during"
195195
"evaluation can allow for larger batch sizes to fit in memory. If not"
196196
"specified, the training batch size (--batch_size) will be used."))
197197

@@ -257,7 +257,7 @@ def define_ncf_flags():
257257
"If passed, training will stop when the evaluation metric HR is "
258258
"greater than or equal to hr_threshold. For dataset ml-1m, the "
259259
"desired hr_threshold is 0.68 which is the result from the paper; "
260-
"For the dataset ml-20m, the threshold can be set as 0.95 which is "
260+
"For dataset ml-20m, the threshold can be set as 0.95 which is "
261261
"achieved by MLPerf implementation."))
262262

263263
flags.DEFINE_enum(
@@ -308,7 +308,7 @@ def define_ncf_flags():
308308
"If set, output the MLPerf compliance logging. This is only useful "
309309
"if one is running the model for MLPerf. See "
310310
"https://github.com/mlperf/policies/blob/master/training_rules.adoc"
311-
"#submission-compliance-logs for details. This uses sudo, and so it may "
311+
"#submission-compliance-logs for details. This uses sudo and so may "
312312
"ask for your password, as root access is needed to clear the system "
313313
"caches, which is required for MLPerf compliance."))
314314

official/vision/modeling/heads/dense_prediction_heads.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,18 @@ def __init__(
143143
'bias_initializer': tf.constant_initializer(-np.log((1 - 0.01) / 0.01)),
144144
'bias_regularizer': self._config_dict['bias_regularizer'],
145145
}
146-
if not self._config_dict['use_separable_conv']:
146+
if self._config_dict['use_separable_conv']:
147+
self._classifier_kwargs.update({
148+
'depthwise_initializer': tf_keras.initializers.RandomNormal(
149+
stddev=0.03
150+
),
151+
'depthwise_regularizer': self._config_dict['kernel_regularizer'],
152+
'pointwise_initializer': tf_keras.initializers.RandomNormal(
153+
stddev=0.03
154+
),
155+
'pointwise_regularizer': self._config_dict['kernel_regularizer'],
156+
})
157+
else:
147158
self._classifier_kwargs.update({
148159
'kernel_initializer': tf_keras.initializers.RandomNormal(stddev=1e-5),
149160
'kernel_regularizer': self._config_dict['kernel_regularizer'],
@@ -159,7 +170,18 @@ def __init__(
159170
'bias_initializer': tf.zeros_initializer(),
160171
'bias_regularizer': self._config_dict['bias_regularizer'],
161172
}
162-
if not self._config_dict['use_separable_conv']:
173+
if self._config_dict['use_separable_conv']:
174+
self._box_regressor_kwargs.update({
175+
'depthwise_initializer': tf_keras.initializers.RandomNormal(
176+
stddev=0.03
177+
),
178+
'depthwise_regularizer': self._config_dict['kernel_regularizer'],
179+
'pointwise_initializer': tf_keras.initializers.RandomNormal(
180+
stddev=0.03
181+
),
182+
'pointwise_regularizer': self._config_dict['kernel_regularizer'],
183+
})
184+
else:
163185
self._box_regressor_kwargs.update({
164186
'kernel_initializer': tf_keras.initializers.RandomNormal(stddev=1e-5),
165187
'kernel_regularizer': self._config_dict['kernel_regularizer'],

official/vision/train.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _run_experiment_with_preemption_recovery(params, model_dir):
7474
preemption_watcher.block_until_worker_exit()
7575
logging.info(
7676
'Some TPU workers had been preempted (message: %s), '
77-
'restarting training from the last checkpoint...',
77+
'retarting training from the last checkpoint...',
7878
preemption_watcher.preemption_message)
7979
keep_training = True
8080
else:

official/vision/utils/object_detection/argmax_matcher.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@
1616
"""Argmax matcher implementation.
1717
1818
This class takes a similarity matrix and matches columns to rows based on the
19-
maximum value per column. One can specify matched_threshold and
19+
maximum value per column. One can specify matched_thresholds and
2020
to prevent columns from matching to rows (generally resulting in a negative
21-
training example) and unmatched_threshold to ignore the match (generally
22-
resulting in neither a positive nor a negative training example).
21+
training example) and unmatched_theshold to ignore the match (generally
22+
resulting in neither a positive or negative training example).
2323
2424
This matcher is used in Fast(er)-RCNN.
2525
26-
Note: Matchers are used in TargetAssigners. There is a create_target_assigner
26+
Note: matchers are used in TargetAssigners. There is a create_target_assigner
2727
factory function for popular implementations.
2828
"""
2929
import tensorflow as tf, tf_keras
@@ -33,22 +33,22 @@
3333

3434

3535
class ArgMaxMatcher(matcher.Matcher):
36-
"""Matcher based on the highest value.
36+
"""Matcher based on highest value.
3737
3838
This class computes matches from a similarity matrix. Each column is matched
3939
to a single row.
4040
41-
To support object detection target assignment, this class enables setting both
41+
To support object detection target assignment this class enables setting both
4242
matched_threshold (upper threshold) and unmatched_threshold (lower threshold)
4343
defining three categories of similarity which define whether examples are
4444
positive, negative, or ignored:
4545
(1) similarity >= matched_threshold: Highest similarity. Matched/Positive!
4646
(2) matched_threshold > similarity >= unmatched_threshold: Medium similarity.
4747
Depending on negatives_lower_than_unmatched, this is either
4848
Unmatched/Negative OR Ignore.
49-
(3) unmatched_threshold > similarity: Lowest similarity. Depending on the flag
49+
(3) unmatched_threshold > similarity: Lowest similarity. Depending on flag
5050
negatives_lower_than_unmatched, either Unmatched/Negative or Ignore.
51-
For ignored matches, this class sets the values in the Match object to -2.
51+
For ignored matches this class sets the values in the Match object to -2.
5252
"""
5353

5454
def __init__(self,

official/vision/utils/object_detection/balanced_positive_negative_sampler.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,21 @@
1414

1515
"""Class to subsample minibatches by balancing positives and negatives.
1616
17-
Subsamples minibatches based on a pre-specified positive fraction in the range
17+
Subsamples minibatches based on a pre-specified positive fraction in range
1818
[0,1]. The class presumes there are many more negatives than positive examples:
1919
if the desired batch_size cannot be achieved with the pre-specified positive
2020
fraction, it fills the rest with negative examples. If this is not sufficient
2121
for obtaining the desired batch_size, it returns fewer examples.
2222
23-
The main function to call is Subsample(self, indicator, labels). For convenience,
24-
one can also call SubsampleWeights(self, weights, labels), which is defined in
23+
The main function to call is Subsample(self, indicator, labels). For convenience
24+
one can also call SubsampleWeights(self, weights, labels) which is defined in
2525
the minibatch_sampler base class.
2626
2727
When is_static is True, it implements a method that guarantees static shapes.
28-
It also ensures that the length of the output of the subsample is always batch_size, even
28+
It also ensures the length of output of the subsample is always batch_size, even
2929
when number of examples set to True in indicator is less than batch_size.
3030
31-
This is originally implemented in the TensorFlow Object Detection API.
31+
This is originally implemented in TensorFlow Object Detection API.
3232
"""
3333

3434
import tensorflow as tf, tf_keras

0 commit comments

Comments
 (0)