repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
libai | libai-main/tests/inference/test_text_classification.py | # coding=utf-8
# Copyright 2021 The OneFlow Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless require... | 3,160 | 38.024691 | 136 | py |
libai | libai-main/tests/structures/test_instance.py | # coding=utf-8
# Copyright 2021 The OneFlow Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless require... | 2,063 | 29.80597 | 86 | py |
libai | libai-main/tests/structures/test_metadata.py | # coding=utf-8
# Copyright 2021 The OneFlow Authors. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless require... | 2,806 | 35.454545 | 95 | py |
libai | libai-main/tests/structures/__init__.py | 0 | 0 | 0 | py | |
libai | libai-main/configs/resmlp_imagenet.py | from libai.config import LazyCall
from .common.models.resmlp.resmlp_12 import model
from .common.models.graph import graph
from .common.train import train
from .common.optim import optim
from .common.data.imagenet import dataloader
import oneflow as flow
import flowvision.transforms as transforms
from flowvision.trans... | 2,630 | 28.233333 | 81 | py |
libai | libai-main/configs/vit_imagenet.py | from libai.config import LazyCall
from .common.models.vit.vit_base_patch16_224 import model
from .common.models.graph import graph
from .common.train import train
from .common.optim import optim
from .common.data.imagenet import dataloader
from flowvision.data import Mixup
from flowvision.loss.cross_entropy import Sof... | 1,670 | 27.810345 | 97 | py |
libai | libai-main/configs/gpt2_pretrain.py | from libai.config import LazyCall
from libai.evaluation import PPLEvaluator
from .common.models.gpt import pretrain_model as model
from .common.train import train
from .common.optim import optim
from .common.data.gpt_dataset import dataloader, tokenization
from .common.models.graph import graph
vocab_file = "./data_t... | 1,427 | 30.733333 | 69 | py |
libai | libai-main/configs/swin_cifar100.py | from libai.config import LazyCall
from .common.models.swin.swin_tiny_patch4_window7_224 import model
from .common.models.graph import graph
from .common.train import train
from .common.optim import optim
from .common.data.cifar100 import dataloader
from flowvision.data import Mixup
from flowvision.loss.cross_entropy i... | 1,606 | 26.237288 | 66 | py |
libai | libai-main/configs/bert_large_pretrain.py | from libai.config import LazyCall
from libai.evaluation import PPLEvaluator
from .common.models.bert import pretrain_model as model
from .common.models.graph import graph
from .common.train import train
from .common.optim import optim
from .common.data.bert_dataset import dataloader, tokenization
vocab_file = "./data_... | 1,192 | 31.243243 | 69 | py |
libai | libai-main/configs/swin_imagenet.py | from libai.config import LazyCall
from .common.models.swin.swin_tiny_patch4_window7_224 import model
from .common.models.graph import graph
from .common.train import train
from .common.optim import optim
from .common.data.imagenet import dataloader
from flowvision.data import Mixup
from flowvision.loss.cross_entropy i... | 1,341 | 25.84 | 66 | py |
libai | libai-main/configs/swinv2_imagenet.py | from libai.config import LazyCall
from .common.models.swinv2.swinv2_tiny_patch4_window8_256 import model
from .common.models.graph import graph
from .common.train import train
from .common.optim import optim
from .common.data.imagenet import dataloader
from flowvision import transforms
from flowvision.data import Mixu... | 4,195 | 28.549296 | 97 | py |
libai | libai-main/configs/t5_large_pretrain.py | from libai.config import LazyCall
from libai.evaluation import PPLEvaluator
from .common.models.t5 import pretrain_model as model
from .common.train import train
from .common.optim import optim
from .common.data.t5_dataset import dataloader, tokenization
from .common.models.graph import graph
vocab_file = "./data_tes... | 1,095 | 31.235294 | 69 | py |
libai | libai-main/configs/swinv2_cifar100.py | from libai.config import LazyCall
from .common.models.swinv2.swinv2_tiny_patch4_window8_256 import model
from .common.models.graph import graph
from .common.train import train
from .common.optim import optim
from .common.data.cifar100 import dataloader
from flowvision import transforms
from flowvision.transforms impo... | 3,754 | 28.566929 | 89 | py |
libai | libai-main/configs/bert_classification.py | from libai.config import LazyCall
from libai.models.bert_model import BertForClassification
from .common.models.bert import cfg as bert_cfg
from .common.models.graph import graph
from .common.train import train
from .common.optim import optim
from .common.data.bert_dataset import tokenization, dataloader
vocab_file = ... | 1,065 | 32.3125 | 69 | py |
libai | libai-main/configs/roberta_pretrain.py | from libai.config import LazyCall
from libai.evaluation import PPLEvaluator
from .common.models.roberta import pretrain_model as model
from .common.models.graph import graph
from .common.train import train
from .common.optim import optim
from .common.data.roberta_dataset import dataloader, tokenization
vocab_file = "... | 1,442 | 31.066667 | 70 | py |
libai | libai-main/configs/common/optim.py | import oneflow as flow
from libai.optim import get_default_optimizer_params
from libai.config import LazyCall
optim = LazyCall(flow.optim.AdamW)(
params=LazyCall(get_default_optimizer_params)(
# params.model is meant to be set to the model object,
# before instantiating the optimizer.
clip... | 547 | 25.095238 | 62 | py |
libai | libai-main/configs/common/train.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.scheduler import WarmupCosineLR
from libai.evaluation import ClsEvaluator
# fmt: off
train = dict(
# Directory where output files are written
output_dir="./output",
# `train_micro_batch_size` is number of samples per batch on ... | 5,991 | 38.682119 | 98 | py |
libai | libai-main/configs/common/models/bert.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.models import BertModel, BertForPreTraining
cfg = dict(
vocab_size=30522,
hidden_size=768,
hidden_layers=24,
num_attention_heads=12,
intermediate_size=4096,
hidden_dropout_prob=0.1,
attention_probs_dropout_prob=0... | 806 | 23.454545 | 54 | py |
libai | libai-main/configs/common/models/roberta.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.models import RobertaModel, RobertaForPreTraining, RobertaForCausalLM
cfg = dict(
vocab_size=50265,
hidden_size=768,
hidden_layers=12,
num_attention_heads=12,
intermediate_size=3072,
hidden_dropout_prob=0.1,
atte... | 894 | 24.571429 | 80 | py |
libai | libai-main/configs/common/models/graph.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.models.utils import GraphBase
graph = dict(
# options for graph or eager mode
enabled=True,
debug=-1, # debug mode for graph
auto_parallel=dict(
enabled=False,
enable_auto_parallel_ignore_user_sbp_config=Fals... | 732 | 28.32 | 94 | py |
libai | libai-main/configs/common/models/gpt.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.models import GPTModel, GPTForPreTraining
cfg = dict(
hidden_layers=6,
vocab_size=30522,
hidden_size=384,
ffn_hidden_size=1536,
num_attention_heads=12,
max_seq_length=1024,
embedding_dropout_prob=0,
attention... | 783 | 23.5 | 53 | py |
libai | libai-main/configs/common/models/t5.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.models import T5Model, T5ForPreTraining
cfg = dict(
vocab_size=30522,
hidden_size=768,
hidden_layers=6,
num_attention_heads=16,
intermediate_size=1536,
hidden_dropout_prob=0.1,
attention_probs_dropout_prob=0.1,
... | 751 | 23.258065 | 52 | py |
libai | libai-main/configs/common/models/resmlp/resmlp_24.py | from libai.config import LazyCall
from libai.models import ResMLP
from .resmlp_12 import cfg
cfg.depth = 24
cfg.init_scale = 1e-5
model = LazyCall(ResMLP)(cfg=cfg)
| 168 | 14.363636 | 33 | py |
libai | libai-main/configs/common/models/resmlp/resmlp_12.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.models import ResMLP
cfg = dict(
img_size=224,
patch_size=16,
in_chans=3,
embed_dim=384,
depth=12,
drop_rate=0.0,
drop_path_rate=0.05,
init_scale=0.1,
num_classes=1000,
loss_func=None,
)
cfg = DictCo... | 365 | 15.636364 | 33 | py |
libai | libai-main/configs/common/models/resmlp/resmlp_36.py | from libai.config import LazyCall
from libai.models import ResMLP
from .resmlp_12 import cfg
cfg.depth = 36
cfg.init_scale = 1e-6
model = LazyCall(ResMLP)(cfg=cfg)
| 168 | 14.363636 | 33 | py |
libai | libai-main/configs/common/models/resmlp/resmlpB_24.py | from libai.config import LazyCall
from libai.models import ResMLP
from .resmlp_12 import cfg
cfg.patch_size = 8
cfg.embed_dim = 768
cfg.depth = 24
cfg.init_scale = 1e-6
model = LazyCall(ResMLP)(cfg=cfg)
| 207 | 15 | 33 | py |
libai | libai-main/configs/common/models/swin/swin_large_patch4_window12_384.py | from libai.config import LazyCall
from libai.models import SwinTransformer
from .swin_tiny_patch4_window7_224 import cfg
cfg.img_size = 384
cfg.embed_dim = 192
cfg.depths = [2, 2, 18, 2]
cfg.num_heads = [6, 12, 24, 48]
cfg.window_size = 12
cfg.drop_path_rate = 0.1
model = LazyCall(SwinTransformer)(cfg=cfg)
| 312 | 19.866667 | 45 | py |
libai | libai-main/configs/common/models/swin/swin_large_patch4_window7_224.py | from libai.config import LazyCall
from libai.models import SwinTransformer
from .swin_tiny_patch4_window7_224 import cfg
cfg.embed_dim = 192
cfg.depths = [2, 2, 18, 2]
cfg.num_heads = [6, 12, 24, 48]
cfg.drop_path_rate = 0.1
model = LazyCall(SwinTransformer)(cfg=cfg)
| 272 | 20 | 45 | py |
libai | libai-main/configs/common/models/swin/swin_tiny_c24_patch4_window8_256.py | from libai.config import LazyCall
from libai.models import SwinTransformer
from .swin_tiny_patch4_window7_224 import cfg
cfg.img_size = 256
cfg.num_heads = [4, 8, 16, 32]
cfg.window_size = 8
model = LazyCall(SwinTransformer)(cfg=cfg)
| 237 | 20.636364 | 45 | py |
libai | libai-main/configs/common/models/swin/swin_tiny_patch4_window7_224.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.models import SwinTransformer
cfg = dict(
img_size=224,
patch_size=4,
in_chans=3,
num_classes=1000,
embed_dim=96,
depths=[2, 2, 6, 2],
num_heads=[3, 6, 12, 24],
window_size=7,
mlp_ratio=4.0,
qkv_bias=... | 513 | 17.357143 | 42 | py |
libai | libai-main/configs/common/models/swin/swin_base_patch4_window12_384.py | from libai.config import LazyCall
from libai.models import SwinTransformer
from .swin_tiny_patch4_window7_224 import cfg
cfg.img_size = 384
cfg.embed_dim = 128
cfg.depths = [2, 2, 18, 2]
cfg.num_heads = [4, 8, 16, 32]
cfg.drop_path_rate = 0.1
model = LazyCall(SwinTransformer)(cfg=cfg)
| 290 | 19.785714 | 45 | py |
libai | libai-main/configs/common/models/swin/swin_base_patch4_window7_224.py | from libai.config import LazyCall
from libai.models import SwinTransformer
from .swin_tiny_patch4_window7_224 import cfg
cfg.embed_dim = 128
cfg.depths = [2, 2, 18, 2]
cfg.num_heads = [4, 8, 16, 32]
cfg.drop_path_rate = 0.5
model = LazyCall(SwinTransformer)(cfg=cfg)
| 271 | 19.923077 | 45 | py |
libai | libai-main/configs/common/models/swin/swin_small_patch4_window7_224.py | from libai.config import LazyCall
from libai.models import SwinTransformer
from .swin_tiny_patch4_window7_224 import cfg
cfg.depths = [2, 2, 18, 2]
cfg.drop_path_rate = 0.3
model = LazyCall(SwinTransformer)(cfg=cfg)
| 219 | 21 | 45 | py |
libai | libai-main/configs/common/models/vit/vit_base_patch32_224.py | from libai.config import LazyCall
from libai.models import VisionTransformer
from .vit_tiny_patch16_224 import cfg
cfg.patch_size = 32
cfg.embed_dim = 768
cfg.num_heads = 12
model = LazyCall(VisionTransformer)(cfg=cfg)
| 223 | 17.666667 | 44 | py |
libai | libai-main/configs/common/models/vit/vit_small_patch32_224.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.models import VisionTransformer
from .vit_tiny_patch16_224 import cfg
cfg.patch_size = 32
cfg.embed_dim = 384
cfg.num_heads = 6
model = LazyCall(VisionTransformer)(cfg=cfg)
| 255 | 18.692308 | 44 | py |
libai | libai-main/configs/common/models/vit/vit_gigantic_patch14_224.py | from libai.config import LazyCall
from libai.models import VisionTransformer
from .vit_tiny_patch16_224 import cfg
cfg.patch_size = 14
cfg.embed_dim = 1664
cfg.mlp_ratio = 64 / 13
cfg.depth = 48
cfg.num_heads = 16
model = LazyCall(VisionTransformer)(cfg=cfg)
| 263 | 17.857143 | 44 | py |
libai | libai-main/configs/common/models/vit/vit_large_patch32_224.py | from libai.config import LazyCall
from libai.models import VisionTransformer
from .vit_tiny_patch16_224 import cfg
cfg.patch_size = 32
cfg.embed_dim = 1024
cfg.depth = 24
cfg.num_heads = 16
model = LazyCall(VisionTransformer)(cfg=cfg)
| 239 | 17.461538 | 44 | py |
libai | libai-main/configs/common/models/vit/vit_giant_patch14_224.py | from libai.config import LazyCall
from libai.models import VisionTransformer
from .vit_tiny_patch16_224 import cfg
cfg.patch_size = 14
cfg.embed_dim = 1408
cfg.mlp_ratio = 48 / 11
cfg.depth = 40
cfg.num_heads = 16
model = LazyCall(VisionTransformer)(cfg=cfg)
| 263 | 17.857143 | 44 | py |
libai | libai-main/configs/common/models/vit/vit_base_patch16_224.py | from libai.config import LazyCall
from libai.models import VisionTransformer
from .vit_tiny_patch16_224 import cfg
cfg.patch_size = 16
cfg.embed_dim = 768
cfg.num_heads = 12
model = LazyCall(VisionTransformer)(cfg=cfg)
| 223 | 17.666667 | 44 | py |
libai | libai-main/configs/common/models/vit/vit_small_patch16_224.py | from libai.config import LazyCall
from libai.models import VisionTransformer
from .vit_tiny_patch16_224 import cfg
cfg.patch_size = 16
cfg.embed_dim = 384
cfg.num_heads = 6
model = LazyCall(VisionTransformer)(cfg=cfg)
| 222 | 17.583333 | 44 | py |
libai | libai-main/configs/common/models/vit/vit_large_patch16_224.py | from libai.config import LazyCall
from libai.models import VisionTransformer
from .vit_tiny_patch16_224 import cfg
cfg.patch_size = 16
cfg.embed_dim = 1024
cfg.depth = 24
cfg.num_heads = 16
model = LazyCall(VisionTransformer)(cfg=cfg)
| 239 | 17.461538 | 44 | py |
libai | libai-main/configs/common/models/vit/vit_huge_patch14_224.py | from libai.config import LazyCall
from libai.models import VisionTransformer
from .vit_tiny_patch16_224 import cfg
cfg.patch_size = 16
cfg.embed_dim = 1280
cfg.depth = 32
cfg.num_heads = 16
model = LazyCall(VisionTransformer)(cfg=cfg)
| 239 | 17.461538 | 44 | py |
libai | libai-main/configs/common/models/vit/vit_tiny_patch16_224.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.models import VisionTransformer
cfg = dict(
img_size=224,
patch_size=16,
in_chans=3,
embed_dim=192,
depth=12,
num_heads=3,
mlp_ratio=4.0,
drop_rate=0.0,
attn_drop_rate=0.0,
drop_path_rate=0.0,
num... | 426 | 16.791667 | 44 | py |
libai | libai-main/configs/common/models/swinv2/swinv2_tiny_patch4_window8_256.py | from omegaconf import DictConfig
from libai.config import LazyCall
from libai.models import SwinTransformerV2
cfg = dict(
img_size=256,
patch_size=4,
in_chans=3,
num_classes=1000,
embed_dim=96,
depths=[2, 2, 6, 2],
num_heads=[3, 6, 12, 24],
window_size=8,
mlp_ratio=4.0,
qkv_bias... | 539 | 19 | 44 | py |
libai | libai-main/configs/common/models/swinv2/swinv2_small_patch4_window16_256.py | from libai.config import LazyCall
from libai.models import SwinTransformerV2
from .swinv2_tiny_patch4_window8_256 import cfg
cfg.window_size = 16
cfg.depths = [2, 2, 18, 2]
cfg.drop_path_rate = 0.3
model = LazyCall(SwinTransformerV2)(cfg=cfg)
| 245 | 23.6 | 47 | py |
libai | libai-main/configs/common/models/swinv2/swinv2_base_patch4_window16_256.py | from libai.config import LazyCall
from libai.models import SwinTransformerV2
from .swinv2_tiny_patch4_window8_256 import cfg
cfg.window_size = 16
cfg.depths = [2, 2, 18, 2]
cfg.num_heads = [4, 8, 16, 32]
cfg.drop_path_rate = 0.5
model = LazyCall(SwinTransformerV2)(cfg=cfg)
| 276 | 24.181818 | 47 | py |
libai | libai-main/configs/common/models/swinv2/swinv2_base_patch4_window8_256.py | from libai.config import LazyCall
from libai.models import SwinTransformerV2
from .swinv2_tiny_patch4_window8_256 import cfg
cfg.depths = [2, 2, 18, 2]
cfg.num_heads = [4, 8, 16, 32]
cfg.drop_path_rate = 0.5
model = LazyCall(SwinTransformerV2)(cfg=cfg)
| 255 | 24.6 | 47 | py |
libai | libai-main/configs/common/models/swinv2/swinv2_small_patch4_window8_256.py | from libai.config import LazyCall
from libai.models import SwinTransformerV2
from .swinv2_tiny_patch4_window8_256 import cfg
cfg.depths = [2, 2, 18, 2]
cfg.drop_path_rate = 0.3
model = LazyCall(SwinTransformerV2)(cfg=cfg)
| 224 | 24 | 47 | py |
libai | libai-main/configs/common/models/swinv2/swinv2_tiny_patch4_window16_256.py | from libai.config import LazyCall
from libai.models import SwinTransformerV2
from .swinv2_tiny_patch4_window8_256 import cfg
cfg.window_size = 16
model = LazyCall(SwinTransformerV2)(cfg=cfg)
| 193 | 23.25 | 47 | py |
libai | libai-main/configs/common/data/cifar100.py | from omegaconf import OmegaConf
from flowvision import transforms
from flowvision.data.mixup import Mixup
from flowvision.transforms import InterpolationMode
from flowvision.transforms.functional import str_to_interp_mode
from libai.data.datasets import CIFAR100Dataset
from libai.data.build import build_image_train_lo... | 2,223 | 26.8 | 89 | py |
libai | libai-main/configs/common/data/gpt_dataset.py | from libai.config import LazyCall
from omegaconf import OmegaConf
from libai.data import build_nlp_test_loader, build_nlp_train_val_test_loader
from libai.data.datasets import GPT2Dataset
from libai.data.data_utils import get_indexed_dataset
from libai.tokenizer import GPT2Tokenizer
tokenization = OmegaConf.create()... | 1,912 | 30.883333 | 90 | py |
libai | libai-main/configs/common/data/bert_dataset.py | from libai.config import LazyCall
from omegaconf import OmegaConf
from libai.data import build_nlp_test_loader, build_nlp_train_val_test_loader
from libai.data.datasets import BertDataset
from libai.data.data_utils import get_indexed_dataset
from libai.tokenizer import BertTokenizer
tokenization = OmegaConf.create()... | 2,097 | 30.313433 | 90 | py |
libai | libai-main/configs/common/data/roberta_dataset.py | from libai.config import LazyCall
from omegaconf import OmegaConf
from libai.data import build_nlp_test_loader, build_nlp_train_val_test_loader
from libai.data.datasets import RobertaDataset
from libai.data.data_utils import get_indexed_dataset
from libai.tokenizer import RobertaTokenizer
tokenization = OmegaConf.cr... | 2,019 | 31.063492 | 90 | py |
libai | libai-main/configs/common/data/t5_dataset.py | from libai.config import LazyCall
from omegaconf import OmegaConf
from libai.data import build_nlp_test_loader, build_nlp_train_val_test_loader
from libai.data.datasets import T5Dataset
from libai.data.data_utils import get_indexed_dataset
from libai.tokenizer import BertTokenizer
tokenization = OmegaConf.create()
... | 2,256 | 29.917808 | 90 | py |
libai | libai-main/configs/common/data/imagenet.py | from omegaconf import OmegaConf
from flowvision import transforms
from flowvision.transforms import InterpolationMode
from flowvision.transforms.functional import str_to_interp_mode
from flowvision.data.constants import (
IMAGENET_DEFAULT_MEAN,
IMAGENET_DEFAULT_STD,
)
from flowvision.data.auto_augment import ra... | 2,535 | 26.868132 | 90 | py |
libai | libai-main/docs/source/conf.py | # Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If ex... | 2,293 | 30.861111 | 79 | py |
IRN | IRN-master/data_process.py | from __future__ import absolute_import
import os
import re
import numpy as np
from collections import Counter
#process Path-QA without KB-memory for other models
# kb: h \t r \t t
# form: question \t ans(ans1/ans2/) \t e1#r1#e2#r2#e3#<end>#e3
def process_data_c(KB_file, data_file, word2id, rel2id, ent2id, words, r... | 8,105 | 27.744681 | 142 | py |
IRN | IRN-master/test.py | import os
import tensorflow as tf
import numpy as np
import time
from data_process import process_data, process_data_c
from utils import MultiAcc, MultiAcc_C, RealAnswer, ScoreRank, InSet, InnerRight
from sklearn import cross_validation, metrics
from model import IRN, IRN_C
flags = tf.app.flags
flags.DEFINE_integer... | 6,041 | 35.179641 | 290 | py |
IRN | IRN-master/utils.py | import os
import math
import random
import numpy as np
import tensorflow as tf
from sklearn import cross_validation, metrics
def norm(matrix):
n = tf.sqrt(tf.reduce_sum(matrix*matrix,1))
return tf.reshape(n,[-1,1])
def MatrixCos(inputdata,key):
#inputdata = [batch,embed]
#key = [slot,embed]
#retur... | 5,374 | 30.804734 | 88 | py |
IRN | IRN-master/model.py | import os
import math
import random
import numpy as np
import tensorflow as tf
from utils import add_gradient_noise,zero_nil_slot,MatrixCos,position_encoding, ScoreRank
class IRN(object):
def __init__(self, config, sess):
self._data_file = config.data_file
self._margin = 4
self._batch_size ... | 27,496 | 45.213445 | 230 | py |
IRN | IRN-master/data_utils.py | from __future__ import absolute_import
import os
import re
import numpy as np
from collections import Counter
#process Path-QA or Conj-QA data&KB
# kb: h \t r \t t
# form: question \t ans \t e1#r1#e2#r2#e3#<end>#e3 \t ans1/ans2/ \t e1#r1#e2///e2#r2#e3#///s#r#t///s#r#t
# form: question \t ans \t e1#r1#... | 10,106 | 28.380814 | 142 | py |
IRN | IRN-master/baseline.py | import os
import math
import random
import numpy as np
import tensorflow as tf
from utils import add_gradient_noise,zero_nil_slot,position_encoding
from tensorflow.contrib.seq2seq import *
from tensorflow.python.layers.core import Dense
class MemN2N(object):
"""End-To-End Memory Network. reference memn2n_qa"""
... | 55,852 | 48.166373 | 211 | py |
IRN | IRN-master/train.py | import os
import tensorflow as tf
import numpy as np
import time
from data_process import process_data, process_data_c
from utils import MultiAcc, MultiAcc_C, RealAnswer, ScoreRank, InSet, InnerRight
from sklearn import cross_validation, metrics
from model import IRN, IRN_C
flags = tf.app.flags
flags.DEFINE_integer... | 10,722 | 42.412955 | 290 | py |
spring | spring-main/setup.py | from setuptools import setup
setup(
name='spring_amr',
version='1.0',
packages=['spring_amr'],
url='https://github.com/SapienzaNLP/spring',
license='CC BY-NC-SA 4.0',
author='Michele Bevilacqua, Rexhina Blloshmi and Roberto Navigli',
author_email='{bevilacqua,blloshmi,navigli}@di.uniroma1.i... | 441 | 33 | 114 | py |
spring | spring-main/spring_amr/entities.py | from collections import defaultdict
def read_entities(sentences, graphs, just_tagged=True):
for i, (s, g) in enumerate(zip(sentences, graphs)):
with_wikis = {}
name_to_entity = {}
name_to_ops = defaultdict(list)
for nt, t in enumerate(g.triples):
n1, rel, n2 = t
... | 848 | 27.3 | 64 | py |
spring | spring-main/spring_amr/optim.py | # taken from
import math
import torch
from torch.optim.optimizer import Optimizer, required
class RAdam(Optimizer):
def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, weight_decay=0, degenerated_to_sgd=True):
if not 0.0 <= lr:
raise ValueError("Invalid learning rate: {}".forma... | 4,345 | 42.46 | 111 | py |
spring | spring-main/spring_amr/penman.py | from penman import load as load_, Graph, Triple
from penman import loads as loads_
from penman import encode as encode_
from penman.model import Model
from penman.models.noop import NoOpModel
from penman.models import amr
op_model = Model()
noop_model = NoOpModel()
amr_model = amr.model
DEFAULT = op_model
def _get_mo... | 1,382 | 24.611111 | 77 | py |
spring | spring-main/spring_amr/utils.py | from glob import glob
from pathlib import Path
import torch
from transformers import AutoConfig
from spring_amr.dataset import AMRDataset, AMRDatasetTokenBatcherAndLoader
from spring_amr.modeling_bart import AMRBartForConditionalGeneration
from spring_amr.tokenization_bart import AMRBartTokenizer, PENMANBartTokenizer... | 5,027 | 28.751479 | 84 | py |
spring | spring-main/spring_amr/dataset.py | import logging
import random
import torch
from cached_property import cached_property
from torch.utils.data import Dataset
from spring_amr.IO import read_raw_amr_data
def reverse_direction(x, y, pad_token_id=1):
input_ids = torch.cat([y['decoder_input_ids'], y['lm_labels'][:, -1:]], 1)
attention_mask = torch.o... | 4,991 | 32.503356 | 105 | py |
spring | spring-main/spring_amr/IO.py | import glob
from typing import List, Union, Iterable
from pathlib import Path
from spring_amr.penman import load as pm_load
def read_raw_amr_data(
paths: List[Union[str, Path]],
use_recategorization=False,
dereify=True,
remove_wiki=False,
):
assert paths
if not isinstance(paths... | 917 | 27.6875 | 131 | py |
spring | spring-main/spring_amr/linearization.py | import abc
import itertools
from collections import deque, defaultdict
import re
from typing import List, Optional, Dict, Any, Set, TypeVar
from cached_property import cached_property
from dataclasses import dataclass
import networkx as nx
import penman
@dataclass
class SemanticGraph:
nodes_var: List[str]
""... | 13,577 | 32.525926 | 156 | py |
spring | spring-main/spring_amr/modeling_bart.py | import copy
import math
import random
from typing import *
import torch
from torch import Tensor
from torch import nn
from torch.nn import functional as F
from transformers import modeling_bart as bart
from transformers.modeling_utils import BeamHypotheses, calc_banned_ngram_tokens, calc_banned_bad_words_ids, \
to... | 60,795 | 46.055728 | 236 | py |
spring | spring-main/spring_amr/__init__.py | __version__ = "0.0.1"
from pathlib import Path
ROOT = Path(__file__).parent.parent
| 85 | 13.333333 | 35 | py |
spring | spring-main/spring_amr/evaluation.py | import datetime
from pathlib import Path
import penman
from sacrebleu import corpus_bleu
import torch
from tqdm import tqdm
import smatch
from spring_amr.dataset import reverse_direction
def predict_amrs(
loader, model, tokenizer, beam_size=1, tokens=None, restore_name_ops=False, return_all=False):
shuf... | 4,920 | 32.937931 | 126 | py |
spring | spring-main/spring_amr/tokenization_bart.py | import copy
import sys
from pathlib import Path
import penman
import regex as re
import torch
from transformers import BartTokenizer
from spring_amr import ROOT, postprocessing
from spring_amr.linearization import AMRTokens, AMRLinearizer
from spring_amr.penman import encode
class AMRBartTokenizer(BartTokenizer):
... | 26,484 | 38.412202 | 120 | py |
spring | spring-main/spring_amr/postprocessing.py | from collections import defaultdict, Counter
import enum
import re
import networkx as nx
import penman
from spring_amr.penman import encode
from spring_amr.linearization import AMRTokens
BACKOFF = penman.Graph([
penman.Triple('d2', ':instance', 'dog'),
penman.Triple('b1', ':instance', 'bark-01'),
penman... | 15,987 | 33.908297 | 126 | py |
spring | spring-main/bin/predict_sentences.py | from pathlib import Path
import penman
import torch
from spring_amr import ROOT
from spring_amr.evaluation import predict_amrs, compute_smatch, predict_sentences, compute_bleu
from spring_amr.penman import encode
from spring_amr.utils import instantiate_loader, instantiate_model_and_tokenizer
if __name__ == '__main_... | 3,988 | 45.383721 | 122 | py |
spring | spring-main/bin/patch_legacy_checkpoint.py | if __name__ == '__main__':
from argparse import ArgumentParser
import torch
parser = ArgumentParser()
parser.add_argument('legacy_checkpoint')
parser.add_argument('patched_checkpoint')
parser.parse_args()
args = parser.parse_args()
to_remove = []
fixed = False
w = torch.load... | 730 | 24.206897 | 62 | py |
spring | spring-main/bin/predict_amrs_from_plaintext.py | from pathlib import Path
import penman
import torch
from tqdm import tqdm
from spring_amr.penman import encode
from spring_amr.utils import instantiate_model_and_tokenizer
def read_file_in_batches(path, batch_size=1000, max_length=100):
data = []
idx = 0
for line in Path(path).read_text().strip().splitl... | 5,603 | 36.610738 | 125 | py |
spring | spring-main/bin/eval_bleu.py | import sys
import argparse
from typing import Iterable, Optional
import sacrebleu
import re
def argument_parser():
parser = argparse.ArgumentParser(description='Preprocess AMR data')
# Multiple input parameters
parser.add_argument(
"--in-tokens",
help="input tokens",
required=True... | 2,151 | 26.240506 | 76 | py |
spring | spring-main/bin/blinkify.py | import blink.main_dense as main_dense
from logging import getLogger
from penman import Triple, Graph
from spring_amr.evaluation import write_predictions
from spring_amr.tokenization_bart import AMRBartTokenizer
import json
from pathlib import Path
from spring_amr.IO import read_raw_amr_data
from spring_amr.entities imp... | 3,827 | 39.294737 | 137 | py |
spring | spring-main/bin/predict_amrs.py | from pathlib import Path
import penman
import torch
from spring_amr import ROOT
from spring_amr.evaluation import predict_amrs, compute_smatch
from spring_amr.penman import encode
from spring_amr.utils import instantiate_loader, instantiate_model_and_tokenizer
if __name__ == '__main__':
from argparse import Arg... | 3,415 | 38.264368 | 125 | py |
spring | spring-main/bin/inspect_.py | import torch
import penman
from spring_amr.utils import instantiate_model_and_tokenizer
if __name__ == '__main__':
from argparse import ArgumentParser
parser = ArgumentParser()
parser.add_argument('--checkpoint', type=str, required=True)
parser.add_argument('--beam-size', type=int, default=1)
pars... | 1,673 | 37.045455 | 106 | py |
spring | spring-main/bin/train.py | from pathlib import Path
import torch
try:
from torch.cuda.amp import autocast
autocast_available = True
except ImportError:
class autocast:
def __init__(self, enabled=True): pass
def __enter__(self): return self
def __exit__(self, exc_type, exc_value, exc_traceback): pass
autoc... | 15,893 | 36.574468 | 115 | py |
AOE-Net | AOE-Net-main/eval_det_thumos.py | import numpy as np
import json
import pickle
from argparse import ArgumentParser
thumos_class = {
7: 'BaseballPitch',
9: 'BasketballDunk',
12: 'Billiards',
21: 'CleanAndJerk',
22: 'CliffDiving',
23: 'CricketBowling',
24: 'CricketShot',
26: 'Diving',
31: 'FrisbeeCatch',
33: 'Gol... | 5,425 | 34.464052 | 131 | py |
AOE-Net | AOE-Net-main/post_processing.py | # -*- coding: utf-8 -*-
import numpy as np
import pandas as pd
import json
import multiprocessing as mp
from tqdm import tqdm
from collections import defaultdict
import pickle as pkl
from utils import iou_with_anchors
def load_json(file):
with open(file) as json_file:
data = json.load(json_file)
... | 9,246 | 35.405512 | 122 | py |
AOE-Net | AOE-Net-main/eval_anet.py | # -*- coding: utf-8 -*-
import sys
sys.path.append('./evaluation_anet')
from eval_proposal import ANETproposal
import matplotlib.pyplot as plt
import numpy as np
def run_evaluation(ground_truth_filename, proposal_filename,
max_avg_nr_proposals=100,
tiou_thresholds=np.linspace(0.5... | 3,295 | 40.2 | 125 | py |
AOE-Net | AOE-Net-main/main.py | import sys
import os
import argparse
from tqdm import tqdm
import pandas as pd
import torch
import torch.nn.parallel
import torch.optim as optim
from torch.utils.tensorboard import SummaryWriter
from models.model import EventDetection
from dataset import VideoDataSet, Collator
from loss_function import bmn_loss_func,... | 10,325 | 43.317597 | 163 | py |
AOE-Net | AOE-Net-main/eval_det_anet.py | import numpy as np
import json
from argparse import ArgumentParser
def load_json(file):
with open(file) as json_file:
data = json.load(json_file)
return data
def add_topk_detection(proposals, class_scores, class_names, k=1):
topk_indices = class_scores.argsort()[-k:][::-1]
topk_scores = ... | 3,831 | 36.568627 | 135 | py |
AOE-Net | AOE-Net-main/eval_thumos.py | # -*- coding: utf-8 -*-
import os
import requests
import pickle
import io
import numpy as np
import matplotlib.pyplot as plt
import pandas as pd
from scipy.interpolate import interp1d
from evaluation_thumos import prop_eval
def run_evaluation(proposal_filename, groundtruth_filename='/home/ngan_uark/tqsang/AEN_BERT/... | 5,009 | 34.785714 | 124 | py |
AOE-Net | AOE-Net-main/utils.py | import numpy as np
import subprocess
import os
def ioa_with_anchors(anchors_min, anchors_max, box_min, box_max):
# calculate the overlap proportion between the anchor and all bbox for supervise signal,
# the length of the anchor is 0.01
len_anchors = anchors_max - anchors_min
int_xmin = np.maximum(anc... | 3,957 | 42.494505 | 112 | py |
AOE-Net | AOE-Net-main/dataset.py | # -*- coding: utf-8 -*-
import os
import json
import numpy as np
import torch
from torch.utils.data.dataset import Dataset
from utils import ioa_with_anchors, iou_with_anchors
def load_json(file):
with open(file) as json_file:
json_data = json.load(json_file)
return json_data
class Collator(o... | 14,047 | 44.170418 | 145 | py |
AOE-Net | AOE-Net-main/loss_function.py | # -*- coding: utf-8 -*-
import torch
import numpy as np
import torch.nn.functional as F
def get_mask(tscale, duration):
bm_mask = []
for idx in range(duration):
mask_vector = [1 for i in range(tscale - idx)
] + [0 for i in range(idx)]
bm_mask.append(mask_vector)
bm_m... | 3,233 | 32 | 89 | py |
AOE-Net | AOE-Net-main/config/defaults.py | from fvcore.common.config import CfgNode
_C = CfgNode()
_C.GPU_IDS = [0]
_C.MODE = 'training'
_C.EVAL_TYPE = 'proposal'
_C.DATASET = 'anet'
_C.USE_ENV = True
_C.USE_AGENT = True
_C.USE_OBJ = True
_C.EVAL_SCORE = 'AUC'
_C.TRAIN = CfgNode()
_C.TRAIN.SPLIT = 'training'
_C.TRAIN.NUM_EPOCHS = 10
_C.TRAIN.BATCH_SIZE = 16... | 2,544 | 26.967033 | 90 | py |
AOE-Net | AOE-Net-main/config/__init__.py | 0 | 0 | 0 | py | |
AOE-Net | AOE-Net-main/models/utils.py | import copy
import torch
import torch.nn as nn
import torch.nn.functional as F
def masked_softmax(vector, mask, dim=-1, memory_efficient=False, mask_fill_value=-1e32):
"""A masked softmax module to correctly implement attention in Pytorch.
Implementation adapted from: https://github.com/allenai/allennlp/blob/... | 8,205 | 44.588889 | 133 | py |
AOE-Net | AOE-Net-main/models/model.py | # -*- coding: utf-8 -*-
import torch
import torch.nn as nn
import torch.nn.functional as F
from .utils import *
from .bmn import BoundaryMatchingNetwork
class EventDetection(nn.Module):
def __init__(self, cfg):
super(EventDetection, self).__init__()
self.use_env_linear = cfg.MODEL.ENV_HIDDEN_DIM ... | 11,169 | 47.146552 | 142 | py |
AOE-Net | AOE-Net-main/models/bmn.py | # -*- coding: utf-8 -*-
import math
import numpy as np
import torch
import torch.nn as nn
class BoundaryMatchingNetwork(nn.Module):
def __init__(self, cfg):
super(BoundaryMatchingNetwork, self).__init__()
self.prop_boundary_ratio = cfg.BMN.PROP_BOUNDARY_RATIO
self.num_sample = cfg.BMN.NUM_... | 5,810 | 41.416058 | 100 | py |
AOE-Net | AOE-Net-main/evaluation_anet/eval_proposal.py | import json
import numpy as np
import pandas as pd
def get_blocked_videos(api=None):
with open('evaluation_anet/api.json', 'r') as f:
return json.load(f)
def interpolated_prec_rec(prec, rec):
"""
Interpolated AP - VOCdevkit from VOC 2011.
"""
mprec = np.hstack([[0], prec, [0]])
mrec ... | 13,403 | 38.307918 | 122 | py |
AOE-Net | AOE-Net-main/evaluation_anet/eval_detection.py | import json
import numpy as np
import pandas as pd
from joblib import Parallel, delayed
def get_blocked_videos(api=None):
with open('evaluation_anet/api.json', 'r') as f:
return json.load(f)
def interpolated_prec_rec(prec, rec):
"""Interpolated AP - VOCdevkit from VOC 2011.
"""
mprec = np.h... | 12,868 | 38.719136 | 110 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.