|
35 | 35 | # are quantized dynamically (per batch) to int8 when the weights are
|
36 | 36 | # quantized to int8.
|
37 | 37 | #
|
38 |
| -# In PyTorch, we have ``torch.quantization.quantize_dynamic`` API support |
39 |
| -# (https://pytorch.org/docs/stable/quantization.html#torch.quantization.quantize_dynamic), |
40 |
| -# which replaces specified modules with dynamic weight-only quantized |
| 38 | +# In PyTorch, we have `torch.quantization.quantize_dynamic API |
| 39 | +# <https://pytorch.org/docs/stable/quantization.html#torch.quantization.quantize_dynamic>`_ |
| 40 | +# ,which replaces specified modules with dynamic weight-only quantized |
41 | 41 | # versions and output the quantized model.
|
42 | 42 | #
|
43 | 43 | # - We demonstrate the accuracy and inference performance results on the
|
44 |
| -# Microsoft Research Paraphrase Corpus (MRPC) task |
45 |
| -# (https://www.microsoft.com/en-us/download/details.aspx?id=52398) in |
46 |
| -# the General Language Understanding Evaluation benchmark (GLUE) |
47 |
| -# (https://gluebenchmark.com/). The MRPC (Dolan and Brockett, 2005) is |
| 44 | +# `Microsoft Research Paraphrase Corpus (MRPC) task <https://www.microsoft.com/en-us/download/details.aspx?id=52398>`_ |
| 45 | +# in the General Language Understanding Evaluation benchmark `(GLUE) |
| 46 | +# <https://gluebenchmark.com/>`_. The MRPC (Dolan and Brockett, 2005) is |
48 | 47 | # a corpus of sentence pairs automatically extracted from online news
|
49 | 48 | # sources, with human annotations of whether the sentences in the pair
|
50 | 49 | # are semantically equivalent. Because the classes are imbalanced (68%
|
51 | 50 | # positive, 32% negative), we follow common practice and report both
|
52 |
| -# accuracy and F1 score |
53 |
| -# (https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html). |
| 51 | +# accuracy and `F1 score <https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html>`_ |
54 | 52 | # MRPC is a common NLP task for language pair classification, as shown
|
55 | 53 | # below.
|
56 | 54 | #
|
|
78 | 76 | #
|
79 | 77 | # To start this tutorial, let’s first follow the installation instructions
|
80 | 78 | # in PyTorch and HuggingFace Github Repo: -
|
81 |
| -# https://github.com/pytorch/pytorch/#installation - |
82 |
| -# https://github.com/huggingface/transformers#installation |
| 79 | +# |
| 80 | +# * https://github.com/pytorch/pytorch/#installation - |
| 81 | +# |
| 82 | +# * https://github.com/huggingface/transformers#installation |
83 | 83 | #
|
84 | 84 | # In addition, we also install ``sklearn`` package, as we will reuse its
|
85 | 85 | # built-in F1 score calculation helper function.
|
|
93 | 93 | ######################################################################
|
94 | 94 | # Because we will be using the experimental parts of the PyTorch, it is
|
95 | 95 | # recommended to install the latest version of torch and torchvision. You
|
96 |
| -# can find the most recent instructions on local installation here |
97 |
| -# https://pytorch.org/get-started/locally/. For example, to install on |
| 96 | +# can find the most recent instructions on local installation `here |
| 97 | +# <https://pytorch.org/get-started/locally/>`_. For example, to install on |
98 | 98 | # Mac:
|
99 | 99 | #
|
100 | 100 | # .. code:: shell
|
|
149 | 149 | # Download the dataset
|
150 | 150 | # --------------------
|
151 | 151 | #
|
152 |
| -# Before running MRPC tasks we download the GLUE data |
153 |
| -# (https://gluebenchmark.com/tasks) by running this script |
154 |
| -# (https://gist.github.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e, |
155 |
| -# https://github.com/nyu-mll/GLUE-baselines/blob/master/download_glue_data.py) |
| 152 | +# Before running MRPC tasks we download the `GLUE data |
| 153 | +# <https://gluebenchmark.com/tasks>`_ by running this `script |
| 154 | +# <https://gist.github.com/W4ngatang/60c2bdb54d156a41194446737ce03e2e>`_ followed by |
| 155 | +# `download_glue_data <https://github.com/nyu-mll/GLUE-baselines/blob/master/download_glue_data.py>`_. |
156 | 156 | # and unpack it to some directory “glue_data/MRPC”.
|
157 | 157 | #
|
158 | 158 |
|
|
176 | 176 | # Convert the texts into features
|
177 | 177 | # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
178 | 178 | #
|
179 |
| -# glue_convert_examples_to_features ( |
180 |
| -# https://github.com/huggingface/transformers/blob/master/transformers/data/processors/glue.py) |
| 179 | +# `glue_convert_examples_to_features <https://github.com/huggingface/transformers/blob/master/transformers/data/processors/glue.py>`_. |
181 | 180 | # load a data file into a list of ``InputFeatures``.
|
182 | 181 | #
|
183 | 182 | # - Tokenize the input sequences;
|
|
190 | 189 | # F1 metric
|
191 | 190 | # ~~~~~~~~~
|
192 | 191 | #
|
193 |
| -# The F1 score |
194 |
| -# (https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html) |
| 192 | +# The `F1 score <https://scikit-learn.org/stable/modules/generated/sklearn.metrics.f1_score.html>`_ |
195 | 193 | # can be interpreted as a weighted average of the precision and recall,
|
196 | 194 | # where an F1 score reaches its best value at 1 and worst score at 0. The
|
197 | 195 | # relative contribution of precision and recall to the F1 score are equal.
|
|
217 | 215 | #
|
218 | 216 | # To fine-tune the pre-trained BERT model (“bert-base-uncased” model in
|
219 | 217 | # HuggingFace transformers) for the MRPC task, you can follow the command
|
220 |
| -# in (https://github.com/huggingface/transformers/tree/master/examples): |
| 218 | +# in `examples<https://github.com/huggingface/transformers/tree/master/examples>`_" |
221 | 219 | #
|
222 | 220 | # ::
|
223 | 221 | #
|
@@ -333,10 +331,8 @@ def set_seed(seed):
|
333 | 331 | # Define the tokenize and evaluation function
|
334 | 332 | # -------------------------------------------
|
335 | 333 | #
|
336 |
| -# We reuse the tokenize and evaluation function from |
337 |
| -# https://github.com/huggingface/transformers/blob/master/examples/run_glue.py. |
| 334 | +# We reuse the tokenize and evaluation function from `huggingface <https://github.com/huggingface/transformers/blob/master/examples/run_glue.py>`_. |
338 | 335 | #
|
339 |
| - |
340 | 336 | # coding=utf-8
|
341 | 337 | # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
|
342 | 338 | # Copyright (c) 2018, NVIDIA CORPORATION. All rights reserved.
|
@@ -598,8 +594,8 @@ def time_model_evaluation(model, configs, tokenizer):
|
598 | 594 | # set multi-thread by ``torch.set_num_threads(N)`` (``N`` is the number of
|
599 | 595 | # intra-op parallelization threads). One preliminary requirement to enable
|
600 | 596 | # the intra-op parallelization support is to build PyTorch with the right
|
601 |
| -# backend such as OpenMP, Native, or TBB |
602 |
| -# (https://pytorch.org/docs/stable/notes/cpu_threading_torchscript_inference.html#build-options). |
| 597 | +# `backend <https://pytorch.org/docs/stable/notes/cpu_threading_torchscript_inference.html#build-options>`_ |
| 598 | +# such as OpenMP, Native or TBB. |
603 | 599 | # You can use ``torch.__config__.parallel_info()`` to check the
|
604 | 600 | # parallelization settings. On the same MacBook Pro using PyTorch with
|
605 | 601 | # Native backend for parallelization, we can get about 46 seconds for
|
|
0 commit comments