예제 #1
0
def main():
    # Get all args
    args = parse_arguments()

    # Logging setup
    if args.verbose:
        set_level(verbose=True)
    elif args.quiet:
        set_level(silent=True)
    else:
        set_level()

    logger = get_logger('main')
    logger.info('Trying to break free - please wait')
    session = Session()

    logger.debug('Starting PortQuiz')
    portquiz = PortQuiz(amount=args.max_ports)
    portquiz.start()

    logger.debug('Starting Online checks')
    try:
        offset, mintime, register = check()
        logger.debug('OnlineStatus completed: %04x %04x %08x', offset, mintime,
                     register)
        online_status_obj = OnlineStatus(offset, mintime, register)
        session.online_status = online_status_obj.get_dict()
    except Exception, e:
        logger.exception('Online status check failed: {}'.format(e))
예제 #2
0
def run(args):
    nli_model_path = 'saved_models/xlnet-base-cased/'
    model_file = os.path.join(nli_model_path, 'pytorch_model.bin')
    config_file = os.path.join(nli_model_path, 'config.json')
    log = get_logger('conduct_test')
    model_name = 'xlnet-base-cased'
    tokenizer = XLNetTokenizer.from_pretrained(model_name, do_lower_case=True)
    xlnet_config = XLNetConfig.from_pretrained(config_file)
    model = XLNetForSequenceClassification.from_pretrained(model_file,
                                                           config=xlnet_config)
    dataset_reader = ConductDatasetReader(args, tokenizer, log)
    file_lines = dataset_reader.get_file_lines('data/dados.tsv')

    results = []
    softmax_fn = torch.nn.Softmax(dim=1)

    model.eval()
    with torch.no_grad():
        for line in tqdm(file_lines):
            premise, hypothesys, conflict = dataset_reader.parse_line(line)
            pair_word_ids, input_mask, pair_segment_ids = dataset_reader.convert_text_to_features(
                premise, hypothesys)
            tensor_word_ids = torch.tensor([pair_word_ids],
                                           dtype=torch.long,
                                           device=args.device)
            tensor_input_mask = torch.tensor([input_mask],
                                             dtype=torch.long,
                                             device=args.device)
            tensor_segment_ids = torch.tensor([pair_segment_ids],
                                              dtype=torch.long,
                                              device=args.device)
            model_input = {
                'input_ids': tensor_word_ids,  # word ids
                'attention_mask': tensor_input_mask,  # input mask
                'token_type_ids': tensor_segment_ids
            }
            outputs = model(**model_input)
            logits = outputs[0]
            nli_scores, nli_class = get_scores_and_class(logits, softmax_fn)
            nli_scores = nli_scores.detach().cpu().numpy()
            results.append({
                "conduct": premise,
                "complaint": hypothesys,
                "nli_class": nli_class,
                "nli_contradiction_score": nli_scores[0],
                "nli_entailment_score": nli_scores[1],
                "nli_neutral_score": nli_scores[2],
                "conflict": conflict
            })

    df = pd.DataFrame(results)
    df.to_csv('results/final_results.tsv', sep='\t', index=False)
예제 #3
0
 def __init__(self, extensions, default_prefix, **kwargs):
     super().__init__(
         help_command=EmbedHelpCommand(),
         activity=Activity(type=ActivityType.playing, name="Booting up..."),
         command_prefix=util.determine_prefix,
         case_insensitive=True,
         allowed_mentions=AllowedMentions(everyone=False),
         max_messages=20000,
         heartbeat_timeout=120,
         owner_id=133311691852218378,
         client_id=500385855072894982,
         status=Status.idle,
         intents=
         Intents(  # https://discordpy.readthedocs.io/en/latest/api.html?highlight=intents#intents
             guilds=True,
             members=True,  # requires verification
             bans=True,
             emojis_and_stickers=True,
             integrations=False,
             webhooks=False,
             invites=False,
             voice_states=False,
             presences=True,  # requires verification
             guild_messages=True,
             dm_messages=True,
             guild_reactions=True,
             dm_reactions=True,
             typing=False,
             message_content=True,  # requires verification
             guild_scheduled_events=False,
             auto_moderation_configuration=False,
             auto_moderation_execution=False,
         ),
         **kwargs,
     )
     self.default_prefix = default_prefix
     self.extensions_to_load = extensions
     self.logger = log.get_logger("MisoBot")
     self.start_time = time()
     self.global_cd = commands.CooldownMapping.from_cooldown(
         15, 60, commands.BucketType.member)
     self.db = maria.MariaDB(self)
     self.cache = cache.Cache(self)
     self.version = "5.1"
     self.extensions_loaded = False
     self.register_hooks()
예제 #4
0
def validate_on_test_set(args, device):
    log = get_logger(f"test-results")
    SEED = 42
    random.seed(SEED)
    np.random.seed(SEED)
    torch.manual_seed(SEED)
    log.info(f'Using device {device}')

    model_name = 'xlnet-base-cased'
    tokenizer = XLNetTokenizer.from_pretrained(model_name, do_lower_case=True)
    xlnet_config = XLNetConfig.from_pretrained(args.config_file)
    data_reader = KaggleMNLIDatasetReader(args, tokenizer, log)
    model = XLNetForSequenceClassification.from_pretrained(args.model_file, config=xlnet_config)

    model.to(device)
    if args.n_gpu > 1:
        model = torch.nn.DataParallel(model)
    log.info(f'Running on {args.n_gpu} GPUS')

    test_executor = KaggleTest(tokenizer, log, data_reader)
    write_kaggle_results("matched", args.test_matched_file, test_executor, device, model)
    write_kaggle_results("mismatched", args.test_mismatched_file, test_executor, device, model)
예제 #5
0
from time import time

import psutil
from discord.ext import commands, tasks
from prometheus_client import Counter, Gauge, Histogram, Summary

from modules import log

logger = log.get_logger(__name__)


class Prometheus(commands.Cog):
    """Collects prometheus metrics"""
    def __init__(self, bot):
        self.bot = bot
        self.ram_gauge = Gauge(
            "miso_memory_usage_bytes",
            "Memory usage of the bot process in bytes.",
        )
        self.cpu_gauge = Gauge(
            "system_cpu_usage_percent",
            "CPU usage of the system in percent.",
            ["core"],
        )
        self.event_counter = Counter(
            "miso_gateway_events_total",
            "Total number of gateway events.",
            ["event_type"],
        )
        self.command_histogram = Histogram(
            "miso_command_response_time_seconds",
예제 #6
0
import traceback
import discord
import asyncio
from discord.ext import commands, flags
from modules import queries, exceptions, log, util, emojis

logger = log.get_logger(__name__)
command_logger = log.get_logger("commands")


class ErrorHander(commands.Cog):
    """Any errors during command invocation will propagate here"""
    def __init__(self, bot):
        self.bot = bot
        self.message_levels = {
            "info": {
                "description_prefix": ":information_source:",
                "color": int("3b88c3", 16),
                "help_footer": False,
            },
            "warning": {
                "description_prefix": ":warning:",
                "color": int("ffcc4d", 16),
                "help_footer": False,
            },
            "error": {
                "description_prefix": ":no_entry:",
                "color": int("be1931", 16),
                "help_footer": False,
            },
            "cooldown": {
예제 #7
0
import argparse
from pathlib import Path

from modules import log
from modules import utils
from modules import config


config = config.get_config('config')
log_path = Path(config['global']['log_path'])

script_name = utils.get_script_name(__file__)
logger = log.get_logger(script_name, log_path=log_path)


def main(args):
  print('this is a template')


def get_parser():
  parser = argparse.ArgumentParser(
      description='Template script description',
      formatter_class=argparse.ArgumentDefaultsHelpFormatter
  )
  parser.add_argument(
      '-t',
      '--test',
      action='store_true',
      help='Test run. No files will be modified'
  )
  return parser
예제 #8
0
def get_train_logger(args):
    logger_name = f'{args.model_name}-batch{args.batch_size}-seq{args.max_seq_len}' \
        f'-warmup{args.warmup_steps}-ep{args.epochs}-{args.dataset_name}'
    return get_logger(logger_name)
예제 #9
0
파일: maria.py 프로젝트: joinemm/miso-bot
import asyncio
import os

import aiomysql

from modules import exceptions, log

logger = log.get_logger(__name__)
log.get_logger("aiomysql")


class MariaDB:
    def __init__(self, bot):
        self.bot = bot
        self.pool = None

    async def wait_for_pool(self):
        i = 0
        while self.pool is None and i < 10:
            logger.warning("Pool not initialized yet. waiting...")
            await asyncio.sleep(1)
            i += 1

        if self.pool is None:
            logger.error("Pool wait timeout! ABORTING")
            return False
        return True

    async def initialize_pool(self):
        cred = {
            "db": os.environ["DB_NAME"],
예제 #10
0
import argparse
from pathlib import Path

from modules import log
from modules import config
from bookmark import Bookmark, BookmarkCollection

config = config.get_config('config')
log_path = Path(config['global']['log_path'])
logger = log.get_logger('bkm-org', log_path=log_path)


def main(args):

    if args['bookmarkfile']:
        collection_fpath = Path(args['bookmarkfile'])
        if not collection_fpath.exists():
            collection_fpath.touch()
    else:
        collection_fpath = Path(config['bkm-org']['collection_fpath'])

    if args['sync']:
        utype = args['sync']
        bc = BookmarkCollection(collection_fpath)
        sync_bookmarks(bc, utype)
        return

    if args['import']:
        itype = args['import'][0]
        fpath = args['import'][1]
        bc = BookmarkCollection()