Ejemplo n.º 1
0
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Nils Schaetti <*****@*****.**>

# Imports
import torch.utils.data
from echotorch import datasets
from echotorch.transforms import text

# Reuters C50 dataset
reutersloader = torch.utils.data.DataLoader(datasets.SFGramDataset(
    tokenizer=text.Token(),
    root="../../data/sfgram/",
    download=True,
    transform=text.GloveVector()),
                                            batch_size=1,
                                            shuffle=True)

# Get training data for this fold
for i, data in enumerate(reutersloader):
    # Inputs and labels
    inputs, labels = data
# end for
Ejemplo n.º 2
0
parser = argparse.ArgumentParser(description="Word embedding for AA")

# Argument
parser.add_argument("--output", type=str, help="Embedding output file", default='.')
parser.add_argument("--dim", type=int, help="Embedding dimension", default=300)
parser.add_argument("--n-features", type=int, help="Number of features", default=30)
parser.add_argument("--no-cuda", action='store_true', default=False, help="Enables CUDA training")
parser.add_argument("--epoch", type=int, help="Epoch", default=300)
parser.add_argument("--steps", type=int, help="Steps to backwards", default=5)
args = parser.parse_args()

# Use CUDA?
args.cuda = not args.no_cuda and torch.cuda.is_available()

# Word embedding
transform = text.Token()

# Reuters C50 dataset
reutersloader = torch.utils.data.DataLoader(datasets.ReutersC50Dataset(download=True, n_authors=15,
                                                                       transform=transform),
                                            batch_size=1, shuffle=False)

# Token to ix
token_to_ix = dict()
ix_to_token = dict()

# Loss function
# loss_function = nn.NLLLoss()
loss_function = nn.CrossEntropyLoss()

# Set fold and training mode