# MIT License
# Copyright (c) 2018 <NAME>

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# Code modified from <NAME>'s seq2seq-summarizer
# repository: https://github.com/ymfa/seq2seq-summarizer

# Copyright (c) 2021 The AlasKA Developers.
# Distributed under the terms of the MIT License.
# SPDX-License_Identifier: MIT
"""
Parameters for the pointer generator model
"""
from typing import Optional
from .get_data_path import get_data_path


class Params:
    """
    Parameters for the Pointer generator model trainng
    """

    # Model architecture
    vocab_size: int = 30000
    hidden_size: int = (
        150  # of the encoder; default decoder size is doubled if encoder is bidi
    )
    dec_hidden_size: Optional[
        int
    ] = 200  # if set, a matrix will transform enc state into dec state
    embed_size: int = 100
    enc_bidi: bool = True
    enc_attn: bool = True  # decoder has attention over encoder states?
    dec_attn: bool = False  # decoder has attention over previous decoder states?
    pointer: bool = (
        True  # use pointer network (copy mechanism) in addition to word generator?
    )
    out_embed_size: Optional[
        int
    ] = None  # if set, use an additional layer before decoder output
    tie_embed: bool = True  # tie the decoder output layer to the input embedding layer?

    # Coverage (to turn on/off, change both `enc_attn_cover` and `cover_loss`)
    enc_attn_cover: bool = True  # provide coverage as input when computing enc attn?
    cover_func: str = (
        "max"  # how to aggregate previous attention distributions? sum or max
    )
    cover_loss: float = (
        1  # add coverage loss if > 0; weight of coverage loss as compared to NLLLoss
    )
    show_cover_loss: bool = (
        False  # include coverage loss in the loss shown in the progress bar?
    )

    # Regularization
    enc_rnn_dropout: float = 0
    dec_in_dropout: float = 0
    dec_rnn_dropout: float = 0
    dec_out_dropout: float = 0

    # Training
    optimizer: str = "Nadam"  # adam or adagrad
    lr: float = 0.001  # learning rate
    adagrad_accumulator: float = 0.1
    lr_decay_step: int = 5  # decay lr every how many epochs?
    lr_decay: Optional[float] = None  # decay lr by multiplying this factor
    batch_size: int = 32
    n_batches: int = 50  # how many batches per epoch CHANGED 1000
    val_batch_size: int = 32
    n_val_batches: int = 10  # how many validation batches per epoch CHANGED 100
    n_epochs: int = 10  # CHANGED 75
    pack_seq: bool = True  # use packed sequence to skip PAD inputs?
    forcing_ratio: float = 0.75  # initial percentage of using teacher forcing
    partial_forcing: bool = (
        True  # in a seq, can some steps be teacher forced and some not?
    )
    forcing_decay_type: Optional[str] = "exp"  # linear, exp, sigmoid, or None
    forcing_decay: float = 0.9999
    sample: bool = (
        True  # are non-teacher forced inputs based on sampling or greedy selection?
    )
    grad_norm: float = 1  # use gradient clipping if > 0; max gradient norm
    # note: enabling reinforcement learning can significantly slow down training
    rl_ratio: float = 0  # use mixed objective if > 0; ratio of RL in the loss function
    rl_ratio_power: float = (
        1  # increase rl_ratio by **= rl_ratio_power after each epoch; (0, 1]
    )
    rl_start_epoch: int = (
        1  # start RL at which epoch (later start can ensure a strong baseline)?
    )

    # Data
    embed_file: Optional[str] = get_data_path(
        "glove.6B.100d.txt"
    )  # use pre-trained embeddings
    data_path: str = str(get_data_path("mnem.gz"))
    # below is validation data commented out for now
    # val_data_path: Optional[str] = str(get_data_path("mnem.val.gz"))
    max_src_len: int = 400  # exclusive of special tokens such as EOS
    max_tgt_len: int = 100  # exclusive of special tokens such as EOS
    truncate_src: bool = (
        True  # truncate to max_src_len? if false, drop example if too long
    )
    truncate_tgt: bool = (
        True  # truncate to max_tgt_len? if false, drop example if too long
    )

    # Saving model automatically during training
    model_path_prefix: Optional[str] = "weights"
    keep_every_epoch: bool = (
        False  # save all epochs, or only the best and the latest one?
    )

    # Testing
    beam_size: int = 4
    min_out_len: int = 60
    max_out_len: Optional[int] = 100
    out_len_in_words: bool = False
    # below is test data commented out for now
    # test_data_path: str = str(get_data_path("mnem.test.gz"))
    test_sample_ratio: float = (
        1  # what portion of the test data is used? (1 for all data)
    )
    test_save_results: bool = True

# MIT License
# Copyright (c) 2018 <NAME>

# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:

# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.

# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

# Code modified from <NAME>'s seq2seq-summarizer
# repository: https://github.com/ymfa/seq2seq-summarizer

# Copyright (c) 2021 The AlasKA Developers.
# Distributed under the terms of the MIT License.
# SPDX-License_Identifier: MIT
"""
Parameters for the pointer generator model
"""
from typing import Optional
from .get_data_path import get_data_path


class Params:
    """
    Parameters for the Pointer generator model trainng
    """

    # Model architecture
    vocab_size: int = 30000
    hidden_size: int = (
        150  # of the encoder; default decoder size is doubled if encoder is bidi
    )
    dec_hidden_size: Optional[
        int
    ] = 200  # if set, a matrix will transform enc state into dec state
    embed_size: int = 100
    enc_bidi: bool = True
    enc_attn: bool = True  # decoder has attention over encoder states?
    dec_attn: bool = False  # decoder has attention over previous decoder states?
    pointer: bool = (
        True  # use pointer network (copy mechanism) in addition to word generator?
    )
    out_embed_size: Optional[
        int
    ] = None  # if set, use an additional layer before decoder output
    tie_embed: bool = True  # tie the decoder output layer to the input embedding layer?

    # Coverage (to turn on/off, change both `enc_attn_cover` and `cover_loss`)
    enc_attn_cover: bool = True  # provide coverage as input when computing enc attn?
    cover_func: str = (
        "max"  # how to aggregate previous attention distributions? sum or max
    )
    cover_loss: float = (
        1  # add coverage loss if > 0; weight of coverage loss as compared to NLLLoss
    )
    show_cover_loss: bool = (
        False  # include coverage loss in the loss shown in the progress bar?
    )

    # Regularization
    enc_rnn_dropout: float = 0
    dec_in_dropout: float = 0
    dec_rnn_dropout: float = 0
    dec_out_dropout: float = 0

    # Training
    optimizer: str = "Nadam"  # adam or adagrad
    lr: float = 0.001  # learning rate
    adagrad_accumulator: float = 0.1
    lr_decay_step: int = 5  # decay lr every how many epochs?
    lr_decay: Optional[float] = None  # decay lr by multiplying this factor
    batch_size: int = 32
    n_batches: int = 50  # how many batches per epoch CHANGED 1000
    val_batch_size: int = 32
    n_val_batches: int = 10  # how many validation batches per epoch CHANGED 100
    n_epochs: int = 10  # CHANGED 75
    pack_seq: bool = True  # use packed sequence to skip PAD inputs?
    forcing_ratio: float = 0.75  # initial percentage of using teacher forcing
    partial_forcing: bool = (
        True  # in a seq, can some steps be teacher forced and some not?
    )
    forcing_decay_type: Optional[str] = "exp"  # linear, exp, sigmoid, or None
    forcing_decay: float = 0.9999
    sample: bool = (
        True  # are non-teacher forced inputs based on sampling or greedy selection?
    )
    grad_norm: float = 1  # use gradient clipping if > 0; max gradient norm
    # note: enabling reinforcement learning can significantly slow down training
    rl_ratio: float = 0  # use mixed objective if > 0; ratio of RL in the loss function
    rl_ratio_power: float = (
        1  # increase rl_ratio by **= rl_ratio_power after each epoch; (0, 1]
    )
    rl_start_epoch: int = (
        1  # start RL at which epoch (later start can ensure a strong baseline)?
    )

    # Data
    embed_file: Optional[str] = get_data_path(
        "glove.6B.100d.txt"
    )  # use pre-trained embeddings
    data_path: str = str(get_data_path("mnem.gz"))
    # below is validation data commented out for now
    # val_data_path: Optional[str] = str(get_data_path("mnem.val.gz"))
    max_src_len: int = 400  # exclusive of special tokens such as EOS
    max_tgt_len: int = 100  # exclusive of special tokens such as EOS
    truncate_src: bool = (
        True  # truncate to max_src_len? if false, drop example if too long
    )
    truncate_tgt: bool = (
        True  # truncate to max_tgt_len? if false, drop example if too long
    )

    # Saving model automatically during training
    model_path_prefix: Optional[str] = "weights"
    keep_every_epoch: bool = (
        False  # save all epochs, or only the best and the latest one?
    )

    # Testing
    beam_size: int = 4
    min_out_len: int = 60
    max_out_len: Optional[int] = 100
    out_len_in_words: bool = False
    # below is test data commented out for now
    # test_data_path: str = str(get_data_path("mnem.test.gz"))
    test_sample_ratio: float = (
        1  # what portion of the test data is used? (1 for all data)
    )
    test_save_results: bool = True

# MIT License # Copyright (c) 2018 <NAME> # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # Code modified from <NAME>'s seq2seq-summarizer # repository: https://github.com/ymfa/seq2seq-summarizer # Copyright (c) 2021 The AlasKA Developers. # Distributed under the terms of the MIT License. # SPDX-License_Identifier: MIT Parameters for the pointer generator model Parameters for the Pointer generator model trainng # Model architecture # of the encoder; default decoder size is doubled if encoder is bidi # if set, a matrix will transform enc state into dec state # decoder has attention over encoder states? # decoder has attention over previous decoder states? # use pointer network (copy mechanism) in addition to word generator? # if set, use an additional layer before decoder output # tie the decoder output layer to the input embedding layer? # Coverage (to turn on/off, change both `enc_attn_cover` and `cover_loss`) # provide coverage as input when computing enc attn? # how to aggregate previous attention distributions? sum or max # add coverage loss if > 0; weight of coverage loss as compared to NLLLoss # include coverage loss in the loss shown in the progress bar? # Regularization # Training # adam or adagrad # learning rate # decay lr every how many epochs? # decay lr by multiplying this factor # how many batches per epoch CHANGED 1000 # how many validation batches per epoch CHANGED 100 # CHANGED 75 # use packed sequence to skip PAD inputs? # initial percentage of using teacher forcing # in a seq, can some steps be teacher forced and some not? # linear, exp, sigmoid, or None # are non-teacher forced inputs based on sampling or greedy selection? # use gradient clipping if > 0; max gradient norm # note: enabling reinforcement learning can significantly slow down training # use mixed objective if > 0; ratio of RL in the loss function # increase rl_ratio by **= rl_ratio_power after each epoch; (0, 1] # start RL at which epoch (later start can ensure a strong baseline)? # Data # use pre-trained embeddings # below is validation data commented out for now # val_data_path: Optional[str] = str(get_data_path("mnem.val.gz")) # exclusive of special tokens such as EOS # exclusive of special tokens such as EOS # truncate to max_src_len? if false, drop example if too long # truncate to max_tgt_len? if false, drop example if too long # Saving model automatically during training # save all epochs, or only the best and the latest one? # Testing # below is test data commented out for now # test_data_path: str = str(get_data_path("mnem.test.gz")) # what portion of the test data is used? (1 for all data)