Unverified Commit 27b3031d authored by Sylvain Gugger's avatar Sylvain Gugger Committed by GitHub
Browse files

Mass conversion of documentation from rst to Markdown (#14866)

* Convert docstrings of all configurations and tokenizers

* Processors and fixes

* Last modeling files and fixes to models

* Pipeline modules

* Utils files

* Data submodule

* All the other files

* Style

* Missing examples

* Style again

* Fix copies

* Say bye bye to rst docstrings forever
parent 18587639
...@@ -126,53 +126,53 @@ class ModelCard: ...@@ -126,53 +126,53 @@ class ModelCard:
@classmethod @classmethod
def from_pretrained(cls, pretrained_model_name_or_path, **kwargs): def from_pretrained(cls, pretrained_model_name_or_path, **kwargs):
r""" r"""
Instantiate a :class:`~transformers.ModelCard` from a pre-trained model model card. Instantiate a [`ModelCard`] from a pre-trained model model card.
Parameters: Parameters:
pretrained_model_name_or_path: either: pretrained_model_name_or_path: either:
- a string, the `model id` of a pretrained model card hosted inside a model repo on huggingface.co. - a string, the *model id* of a pretrained model card hosted inside a model repo on huggingface.co.
Valid model ids can be located at the root-level, like ``bert-base-uncased``, or namespaced under a Valid model ids can be located at the root-level, like `bert-base-uncased`, or namespaced under a
user or organization name, like ``dbmdz/bert-base-german-cased``. user or organization name, like `dbmdz/bert-base-german-cased`.
- a path to a `directory` containing a model card file saved using the - a path to a *directory* containing a model card file saved using the
:func:`~transformers.ModelCard.save_pretrained` method, e.g.: ``./my_model_directory/``. [`~ModelCard.save_pretrained`] method, e.g.: `./my_model_directory/`.
- a path or url to a saved model card JSON `file`, e.g.: ``./my_model_directory/modelcard.json``. - a path or url to a saved model card JSON *file*, e.g.: `./my_model_directory/modelcard.json`.
cache_dir: (`optional`) string: cache_dir: (*optional*) string:
Path to a directory in which a downloaded pre-trained model card should be cached if the standard cache Path to a directory in which a downloaded pre-trained model card should be cached if the standard cache
should not be used. should not be used.
kwargs: (`optional`) dict: key/value pairs with which to update the ModelCard object after loading. kwargs: (*optional*) dict: key/value pairs with which to update the ModelCard object after loading.
- The values in kwargs of any keys which are model card attributes will be used to override the loaded - The values in kwargs of any keys which are model card attributes will be used to override the loaded
values. values.
- Behavior concerning key/value pairs whose keys are *not* model card attributes is controlled by the - Behavior concerning key/value pairs whose keys are *not* model card attributes is controlled by the
`return_unused_kwargs` keyword parameter. *return_unused_kwargs* keyword parameter.
proxies: (`optional`) dict, default None: proxies: (*optional*) dict, default None:
A dictionary of proxy servers to use by protocol or endpoint, e.g.: {'http': 'foo.bar:3128', A dictionary of proxy servers to use by protocol or endpoint, e.g.: {'http': 'foo.bar:3128',
'http://hostname': 'foo.bar:4012'}. The proxies are used on each request. 'http://hostname': 'foo.bar:4012'}. The proxies are used on each request.
find_from_standard_name: (`optional`) boolean, default True: find_from_standard_name: (*optional*) boolean, default True:
If the pretrained_model_name_or_path ends with our standard model or config filenames, replace them If the pretrained_model_name_or_path ends with our standard model or config filenames, replace them
with our standard modelcard filename. Can be used to directly feed a model/config url and access the with our standard modelcard filename. Can be used to directly feed a model/config url and access the
colocated modelcard. colocated modelcard.
return_unused_kwargs: (`optional`) bool: return_unused_kwargs: (*optional*) bool:
- If False, then this function returns just the final model card object. - If False, then this function returns just the final model card object.
- If True, then this functions returns a tuple `(model card, unused_kwargs)` where `unused_kwargs` is a - If True, then this functions returns a tuple *(model card, unused_kwargs)* where *unused_kwargs* is a
dictionary consisting of the key/value pairs whose keys are not model card attributes: ie the part of dictionary consisting of the key/value pairs whose keys are not model card attributes: ie the part of
kwargs which has not been used to update `ModelCard` and is otherwise ignored. kwargs which has not been used to update *ModelCard* and is otherwise ignored.
Examples:: Examples:
```python
modelcard = ModelCard.from_pretrained('bert-base-uncased') # Download model card from huggingface.co and cache. modelcard = ModelCard.from_pretrained('bert-base-uncased') # Download model card from huggingface.co and cache.
modelcard = ModelCard.from_pretrained('./test/saved_model/') # E.g. model card was saved using `save_pretrained('./test/saved_model/')` modelcard = ModelCard.from_pretrained('./test/saved_model/') # E.g. model card was saved using *save_pretrained('./test/saved_model/')*
modelcard = ModelCard.from_pretrained('./test/saved_model/modelcard.json') modelcard = ModelCard.from_pretrained('./test/saved_model/modelcard.json')
modelcard = ModelCard.from_pretrained('bert-base-uncased', output_attentions=True, foo=False) modelcard = ModelCard.from_pretrained('bert-base-uncased', output_attentions=True, foo=False)
```"""
"""
# This imports every model so let's do it dynamically here. # This imports every model so let's do it dynamically here.
from transformers.models.auto.configuration_auto import ALL_PRETRAINED_CONFIG_ARCHIVE_MAP from transformers.models.auto.configuration_auto import ALL_PRETRAINED_CONFIG_ARCHIVE_MAP
......
...@@ -69,7 +69,7 @@ def rename_key_and_reshape_tensor( ...@@ -69,7 +69,7 @@ def rename_key_and_reshape_tensor(
"""Rename PT weight names to corresponding Flax weight names and reshape tensor if necessary""" """Rename PT weight names to corresponding Flax weight names and reshape tensor if necessary"""
def is_key_or_prefix_key_in_dict(key: Tuple[str]) -> bool: def is_key_or_prefix_key_in_dict(key: Tuple[str]) -> bool:
"""Checks if ``key`` of ``(prefix,) + key`` is in random_flax_state_dict""" """Checks if `key` of `(prefix,) + key` is in random_flax_state_dict"""
return len(set(random_flax_state_dict) & set([key, (model_prefix,) + key])) > 0 return len(set(random_flax_state_dict) & set([key, (model_prefix,) + key])) > 0
# layer norm # layer norm
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -35,62 +35,61 @@ ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP = { ...@@ -35,62 +35,61 @@ ALBERT_PRETRAINED_CONFIG_ARCHIVE_MAP = {
class AlbertConfig(PretrainedConfig): class AlbertConfig(PretrainedConfig):
r""" r"""
This is the configuration class to store the configuration of a :class:`~transformers.AlbertModel` or a This is the configuration class to store the configuration of a [`AlbertModel`] or a
:class:`~transformers.TFAlbertModel`. It is used to instantiate an ALBERT model according to the specified [`TFAlbertModel`]. It is used to instantiate an ALBERT model according to the specified
arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a similar arguments, defining the model architecture. Instantiating a configuration with the defaults will yield a similar
configuration to that of the ALBERT `xxlarge <https://huggingface.co/albert-xxlarge-v2>`__ architecture. configuration to that of the ALBERT [xxlarge](https://huggingface.co/albert-xxlarge-v2) architecture.
Configuration objects inherit from :class:`~transformers.PretrainedConfig` and can be used to control the model Configuration objects inherit from [`PretrainedConfig`] and can be used to control the model
outputs. Read the documentation from :class:`~transformers.PretrainedConfig` for more information. outputs. Read the documentation from [`PretrainedConfig`] for more information.
Args: Args:
vocab_size (:obj:`int`, `optional`, defaults to 30000): vocab_size (`int`, *optional*, defaults to 30000):
Vocabulary size of the ALBERT model. Defines the number of different tokens that can be represented by the Vocabulary size of the ALBERT model. Defines the number of different tokens that can be represented by the
:obj:`inputs_ids` passed when calling :class:`~transformers.AlbertModel` or `inputs_ids` passed when calling [`AlbertModel`] or
:class:`~transformers.TFAlbertModel`. [`TFAlbertModel`].
embedding_size (:obj:`int`, `optional`, defaults to 128): embedding_size (`int`, *optional*, defaults to 128):
Dimensionality of vocabulary embeddings. Dimensionality of vocabulary embeddings.
hidden_size (:obj:`int`, `optional`, defaults to 4096): hidden_size (`int`, *optional*, defaults to 4096):
Dimensionality of the encoder layers and the pooler layer. Dimensionality of the encoder layers and the pooler layer.
num_hidden_layers (:obj:`int`, `optional`, defaults to 12): num_hidden_layers (`int`, *optional*, defaults to 12):
Number of hidden layers in the Transformer encoder. Number of hidden layers in the Transformer encoder.
num_hidden_groups (:obj:`int`, `optional`, defaults to 1): num_hidden_groups (`int`, *optional*, defaults to 1):
Number of groups for the hidden layers, parameters in the same group are shared. Number of groups for the hidden layers, parameters in the same group are shared.
num_attention_heads (:obj:`int`, `optional`, defaults to 64): num_attention_heads (`int`, *optional*, defaults to 64):
Number of attention heads for each attention layer in the Transformer encoder. Number of attention heads for each attention layer in the Transformer encoder.
intermediate_size (:obj:`int`, `optional`, defaults to 16384): intermediate_size (`int`, *optional*, defaults to 16384):
The dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder. The dimensionality of the "intermediate" (often named feed-forward) layer in the Transformer encoder.
inner_group_num (:obj:`int`, `optional`, defaults to 1): inner_group_num (`int`, *optional*, defaults to 1):
The number of inner repetition of attention and ffn. The number of inner repetition of attention and ffn.
hidden_act (:obj:`str` or :obj:`Callable`, `optional`, defaults to :obj:`"gelu_new"`): hidden_act (`str` or `Callable`, *optional*, defaults to `"gelu_new"`):
The non-linear activation function (function or string) in the encoder and pooler. If string, The non-linear activation function (function or string) in the encoder and pooler. If string,
:obj:`"gelu"`, :obj:`"relu"`, :obj:`"silu"` and :obj:`"gelu_new"` are supported. `"gelu"`, `"relu"`, `"silu"` and `"gelu_new"` are supported.
hidden_dropout_prob (:obj:`float`, `optional`, defaults to 0): hidden_dropout_prob (`float`, *optional*, defaults to 0):
The dropout probability for all fully connected layers in the embeddings, encoder, and pooler. The dropout probability for all fully connected layers in the embeddings, encoder, and pooler.
attention_probs_dropout_prob (:obj:`float`, `optional`, defaults to 0): attention_probs_dropout_prob (`float`, *optional*, defaults to 0):
The dropout ratio for the attention probabilities. The dropout ratio for the attention probabilities.
max_position_embeddings (:obj:`int`, `optional`, defaults to 512): max_position_embeddings (`int`, *optional*, defaults to 512):
The maximum sequence length that this model might ever be used with. Typically set this to something large The maximum sequence length that this model might ever be used with. Typically set this to something large
(e.g., 512 or 1024 or 2048). (e.g., 512 or 1024 or 2048).
type_vocab_size (:obj:`int`, `optional`, defaults to 2): type_vocab_size (`int`, *optional*, defaults to 2):
The vocabulary size of the :obj:`token_type_ids` passed when calling :class:`~transformers.AlbertModel` or The vocabulary size of the `token_type_ids` passed when calling [`AlbertModel`] or
:class:`~transformers.TFAlbertModel`. [`TFAlbertModel`].
initializer_range (:obj:`float`, `optional`, defaults to 0.02): initializer_range (`float`, *optional*, defaults to 0.02):
The standard deviation of the truncated_normal_initializer for initializing all weight matrices. The standard deviation of the truncated_normal_initializer for initializing all weight matrices.
layer_norm_eps (:obj:`float`, `optional`, defaults to 1e-12): layer_norm_eps (`float`, *optional*, defaults to 1e-12):
The epsilon used by the layer normalization layers. The epsilon used by the layer normalization layers.
classifier_dropout_prob (:obj:`float`, `optional`, defaults to 0.1): classifier_dropout_prob (`float`, *optional*, defaults to 0.1):
The dropout ratio for attached classifiers. The dropout ratio for attached classifiers.
position_embedding_type (:obj:`str`, `optional`, defaults to :obj:`"absolute"`): position_embedding_type (`str`, *optional*, defaults to `"absolute"`):
Type of position embedding. Choose one of :obj:`"absolute"`, :obj:`"relative_key"`, Type of position embedding. Choose one of `"absolute"`, `"relative_key"`,
:obj:`"relative_key_query"`. For positional embeddings use :obj:`"absolute"`. For more information on `"relative_key_query"`. For positional embeddings use `"absolute"`. For more information on
:obj:`"relative_key"`, please refer to `Self-Attention with Relative Position Representations (Shaw et al.) `"relative_key"`, please refer to [Self-Attention with Relative Position Representations (Shaw et al.)](https://arxiv.org/abs/1803.02155). For more information on `"relative_key_query"`, please refer to
<https://arxiv.org/abs/1803.02155>`__. For more information on :obj:`"relative_key_query"`, please refer to *Method 4* in [Improve Transformer Models with Better Relative Position Embeddings (Huang et al.)](https://arxiv.org/abs/2009.13658).
`Method 4` in `Improve Transformer Models with Better Relative Position Embeddings (Huang et al.)
<https://arxiv.org/abs/2009.13658>`__.
Examples:: Examples:
```python
>>> from transformers import AlbertConfig, AlbertModel >>> from transformers import AlbertConfig, AlbertModel
>>> # Initializing an ALBERT-xxlarge style configuration >>> # Initializing an ALBERT-xxlarge style configuration
>>> albert_xxlarge_configuration = AlbertConfig() >>> albert_xxlarge_configuration = AlbertConfig()
...@@ -107,7 +106,7 @@ class AlbertConfig(PretrainedConfig): ...@@ -107,7 +106,7 @@ class AlbertConfig(PretrainedConfig):
>>> # Accessing the model configuration >>> # Accessing the model configuration
>>> configuration = model.config >>> configuration = model.config
""" ```"""
model_type = "albert" model_type = "albert"
......
...@@ -742,8 +742,9 @@ class FlaxAlbertForPreTraining(FlaxAlbertPreTrainedModel): ...@@ -742,8 +742,9 @@ class FlaxAlbertForPreTraining(FlaxAlbertPreTrainedModel):
FLAX_ALBERT_FOR_PRETRAINING_DOCSTRING = """ FLAX_ALBERT_FOR_PRETRAINING_DOCSTRING = """
Returns: Returns:
Example:: Example:
```python
>>> from transformers import AlbertTokenizer, FlaxAlbertForPreTraining >>> from transformers import AlbertTokenizer, FlaxAlbertForPreTraining
>>> tokenizer = AlbertTokenizer.from_pretrained('albert-base-v2') >>> tokenizer = AlbertTokenizer.from_pretrained('albert-base-v2')
...@@ -754,6 +755,7 @@ FLAX_ALBERT_FOR_PRETRAINING_DOCSTRING = """ ...@@ -754,6 +755,7 @@ FLAX_ALBERT_FOR_PRETRAINING_DOCSTRING = """
>>> prediction_logits = outputs.prediction_logits >>> prediction_logits = outputs.prediction_logits
>>> seq_relationship_logits = outputs.sop_logits >>> seq_relationship_logits = outputs.sop_logits
```
""" """
overwrite_call_docstring( overwrite_call_docstring(
......
...@@ -885,8 +885,9 @@ class TFAlbertForPreTraining(TFAlbertPreTrainedModel, TFAlbertPreTrainingLoss): ...@@ -885,8 +885,9 @@ class TFAlbertForPreTraining(TFAlbertPreTrainedModel, TFAlbertPreTrainingLoss):
r""" r"""
Return: Return:
Example:: Example:
```python
>>> import tensorflow as tf >>> import tensorflow as tf
>>> from transformers import AlbertTokenizer, TFAlbertForPreTraining >>> from transformers import AlbertTokenizer, TFAlbertForPreTraining
...@@ -898,7 +899,7 @@ class TFAlbertForPreTraining(TFAlbertPreTrainedModel, TFAlbertPreTrainingLoss): ...@@ -898,7 +899,7 @@ class TFAlbertForPreTraining(TFAlbertPreTrainedModel, TFAlbertPreTrainingLoss):
>>> prediction_logits = outputs.prediction_logits >>> prediction_logits = outputs.prediction_logits
>>> sop_logits = outputs.sop_logits >>> sop_logits = outputs.sop_logits
""" ```"""
inputs = input_processing( inputs = input_processing(
func=self.call, func=self.call,
......
...@@ -120,60 +120,63 @@ def get_class_from_dynamic_module( ...@@ -120,60 +120,63 @@ def get_class_from_dynamic_module(
""" """
Extracts a class from a module file, present in the local folder or repository of a model. Extracts a class from a module file, present in the local folder or repository of a model.
.. warning:: <Tip warning={true}>
Calling this function will execute the code in the module file found locally or downloaded from the Hub. It Calling this function will execute the code in the module file found locally or downloaded from the Hub. It
should therefore only be called on trusted repos. should therefore only be called on trusted repos.
</Tip>
Args: Args:
pretrained_model_name_or_path (:obj:`str` or :obj:`os.PathLike`): pretrained_model_name_or_path (`str` or `os.PathLike`):
This can be either: This can be either:
- a string, the `model id` of a pretrained model configuration hosted inside a model repo on - a string, the *model id* of a pretrained model configuration hosted inside a model repo on
huggingface.co. Valid model ids can be located at the root-level, like ``bert-base-uncased``, or huggingface.co. Valid model ids can be located at the root-level, like `bert-base-uncased`, or
namespaced under a user or organization name, like ``dbmdz/bert-base-german-cased``. namespaced under a user or organization name, like `dbmdz/bert-base-german-cased`.
- a path to a `directory` containing a configuration file saved using the - a path to a *directory* containing a configuration file saved using the
:func:`~transformers.PreTrainedTokenizer.save_pretrained` method, e.g., ``./my_model_directory/``. [`~PreTrainedTokenizer.save_pretrained`] method, e.g., `./my_model_directory/`.
module_file (:obj:`str`): module_file (`str`):
The name of the module file containing the class to look for. The name of the module file containing the class to look for.
class_name (:obj:`str`): class_name (`str`):
The name of the class to import in the module. The name of the class to import in the module.
cache_dir (:obj:`str` or :obj:`os.PathLike`, `optional`): cache_dir (`str` or `os.PathLike`, *optional*):
Path to a directory in which a downloaded pretrained model configuration should be cached if the standard Path to a directory in which a downloaded pretrained model configuration should be cached if the standard
cache should not be used. cache should not be used.
force_download (:obj:`bool`, `optional`, defaults to :obj:`False`): force_download (`bool`, *optional*, defaults to `False`):
Whether or not to force to (re-)download the configuration files and override the cached versions if they Whether or not to force to (re-)download the configuration files and override the cached versions if they
exist. exist.
resume_download (:obj:`bool`, `optional`, defaults to :obj:`False`): resume_download (`bool`, *optional*, defaults to `False`):
Whether or not to delete incompletely received file. Attempts to resume the download if such a file exists. Whether or not to delete incompletely received file. Attempts to resume the download if such a file exists.
proxies (:obj:`Dict[str, str]`, `optional`): proxies (`Dict[str, str]`, *optional*):
A dictionary of proxy servers to use by protocol or endpoint, e.g., :obj:`{'http': 'foo.bar:3128', A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128', 'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request. use_auth_token (`str` or *bool*, *optional*):
use_auth_token (:obj:`str` or `bool`, `optional`): The token to use as HTTP bearer authorization for remote files. If `True`, will use the token
The token to use as HTTP bearer authorization for remote files. If :obj:`True`, will use the token generated when running `transformers-cli login` (stored in `~/.huggingface`).
generated when running :obj:`transformers-cli login` (stored in :obj:`~/.huggingface`). revision(`str`, *optional*, defaults to `"main"`):
revision(:obj:`str`, `optional`, defaults to :obj:`"main"`):
The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
git-based system for storing models and other artifacts on huggingface.co, so ``revision`` can be any git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
identifier allowed by git. identifier allowed by git.
local_files_only (:obj:`bool`, `optional`, defaults to :obj:`False`): local_files_only (`bool`, *optional*, defaults to `False`):
If :obj:`True`, will only try to load the tokenizer configuration from local files. If `True`, will only try to load the tokenizer configuration from local files.
.. note:: <Tip>
Passing :obj:`use_auth_token=True` is required when you want to use a private model. Passing `use_auth_token=True` is required when you want to use a private model.
</Tip>
Returns: Returns:
:obj:`type`: The class, dynamically imported from the module. `type`: The class, dynamically imported from the module.
Examples:: Examples:
# Download module `modeling.py` from huggingface.co and cache then extract the class `MyBertModel` from this ```python
# Download module *modeling.py* from huggingface.co and cache then extract the class *MyBertModel* from this
# module. # module.
cls = get_class_from_dynamic_module("sgugger/my-bert-model", "modeling.py", "MyBertModel") cls = get_class_from_dynamic_module("sgugger/my-bert-model", "modeling.py", "MyBertModel")
""" ```"""
if is_offline_mode() and not local_files_only: if is_offline_mode() and not local_files_only:
logger.info("Offline mode: forcing local_files_only=True") logger.info("Offline mode: forcing local_files_only=True")
local_files_only = True local_files_only = True
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment