text:
import subprocess
from subprocess import PIPE, STDOUT, Popen

import config
from util import plane_2_line

import numpy as np

class HumanPlayer:
    def make_move(self, current_node):
        human_input = -1
        while True:
            human_input_str = input(">")
            if human_input_str == "pass":
                human_input = config.pass_move
            else:
                human_input = plane_2_line(human_input_str)

            if human_input is None or current_node.legal_moves[human_input] == 0:
                print("illegal.")
            else:
                return human_input

ext: py

reason: import numpy


text:
# Copyright 2017 Amazon.com, Inc. or its affiliates. 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.
# A copy of the License is located at
#
#   http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is distributed
# on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
# express or implied. See the License for the specific language governing
# permissions and limitations under the License.
import os
import pytest

from pyspark import SparkConf, SparkContext

from sagemaker_pyspark import (S3DataPath, EndpointCreationPolicy, RandomNamePolicyFactory,
                               SageMakerClients, IAMRole, classpath_jars)
from sagemaker_pyspark.algorithms import FactorizationMachinesRegressor

from sagemaker_pyspark.transformation.serializers import ProtobufRequestRowSerializer
from sagemaker_pyspark.transformation.deserializers \
    import FactorizationMachinesRegressorDeserializer

@pytest.fixture(autouse=True)
def with_spark_context():
    os.environ['SPARK_CLASSPATH'] = ":".join(classpath_jars())
    conf = (SparkConf()
            .set("spark.driver.extraClassPath", os.environ['SPARK_CLASSPATH']))

    if SparkContext._active_spark_context is None:
        SparkContext(conf=conf)

    yield SparkContext._active_spark_context

    # TearDown
    SparkContext.stop(SparkContext._active_spark_context)

def get_factorization_machines_regressor():
    training_instance_type = "c4.8xlarge"
    training_instance_count = 3
    endpoint_instance_type = "c4.8xlarge"
    endpoint_initial_instance_count = 3
    estimator = FactorizationMachinesRegressor(
        trainingInstanceType=training_instance_type,
        trainingInstanceCount=training_instance_count,
        endpointInstanceType=endpoint_instance_type,
        endpointInitialInstanceCount=endpoint_initial_instance_count,
        sagemakerRole=IAMRole("some-role"),
        trainingProjectedColumns=None,
        trainingS3DataDistribution="by-key",
        trainingInputMode="File",
        endpointCreationPolicy=EndpointCreationPolicy.CREATE_ON_TRANSFORM,
        modelPrependInputRowsToTransformationRows=True,
        namePolicyFactory=RandomNamePolicyFactory(),
        uid="sagemaker")
    return estimator

def test_can_create_regressor_from_configured_role():
    training_instance_type = "c4.8xlarge"
    training_instance_count = 3
    endpoint_instance_type = "c4.8xlarge"
    endpoint_initial_instance_count = 3
    estimator = FactorizationMachinesRegressor(
        trainingInstanceType=training_instance_type,
        trainingInstanceCount=training_instance_count,
        endpointInstanceType=endpoint_instance_type,
        endpointInitialInstanceCount=endpoint_initial_instance_count,
        trainingProjectedColumns=None,
        trainingS3DataDistribution="by-key",
        trainingInputMode="File",
        endpointCreationPolicy=EndpointCreationPolicy.CREATE_ON_TRANSFORM,
        modelPrependInputRowsToTransformationRows=True,
        namePolicyFactory=RandomNamePolicyFactory(),
        uid="sagemaker")
    return estimator

def test_factorization_machines_regressor_has_correct_defaults():
    estimator = get_factorization_machines_regressor()
    assert estimator.trainingSparkDataFormat == "sagemaker"

def test_factorizationMachinesRegressor_passes_correct_params_to_scala():

    training_instance_type = "c4.8xlarge"
    training_instance_count = 3
    endpoint_instance_type = "c4.8xlarge"
    endpoint_initial_instance_count = 3

    training_bucket = "random-bucket"
    input_prefix = "factorization-machines-regressor-training"
    output_prefix = "factorization-machines-regressor-out"
    integTestingRole = "arn:aws:iam::123456789:role/SageMakerRole"

    estimator = FactorizationMachinesRegressor(
        trainingInstanceType=training_instance_type,
        trainingInstanceCount=training_instance_count,
        endpointInstanceType=endpoint_instance_type,
        endpointInitialInstanceCount=endpoint_initial_instance_count,
        sagemakerRole=IAMRole(integTestingRole),
        requestRowSerializer=ProtobufRequestRowSerializer(),
        responseRowDeserializer=FactorizationMachinesRegressorDeserializer(),
        trainingInstanceVolumeSizeInGB=2048,
        trainingInputS3DataPath=S3DataPath(training_bucket, input_prefix),
        trainingOutputS3DataPath=S3DataPath(training_bucket, output_prefix),
        trainingMaxRuntimeInSeconds=1,
        endpointCreationPolicy=EndpointCreationPolicy.CREATE_ON_TRANSFORM,
        sagemakerClient=SageMakerClients.create_sagemaker_client(),
        s3Client=SageMakerClients.create_s3_default_client(),
        stsClient=SageMakerClients.create_sts_default_client(),
        modelPrependInputRowsToTransformationRows=True,
        namePolicyFactory=RandomNamePolicyFactory(),
        uid="sagemaker")

    assert estimator.trainingInputS3DataPath.bucket == training_bucket
    assert estimator.trainingInputS3DataPath.objectPath == input_prefix
    assert estimator.trainingInstanceCount == training_instance_count
    assert estimator.trainingInstanceType == training_instance_type
    assert estimator.endpointInstanceType == endpoint_instance_type
    assert estimator.endpointInitialInstanceCount == endpoint_initial_instance_count
    assert estimator.trainingInstanceVolumeSizeInGB == 2048
    assert estimator.trainingMaxRuntimeInSeconds == 1
    assert estimator.trainingKmsKeyId is None

max_stars_repo_name: hyandell/sagemaker-spark

max_issues_repo_name: hyandell/sagemaker-spark

max_forks_repo_name: hyandell/sagemaker-spark

reason: from sage


text:
import glob
import os
import shutil
import sys
from os.path import join
import subprocess
import struct

import numpy
from Cython.Build import cythonize
from setuptools import setup, find_packages
from setuptools.extension import Extension
from setuptools.dist import Distribution
import versioneer

DEVELOP = False
CYTHON_COVERAGE = bool(os.environ.get('CYTHON_COVERAGE', False))

try:
    import Cython.Tempita as tempita
except ImportError:
    try:
        import tempita
    except ImportError:
        raise ImportError('tempita required to install, '
                          'use pip install tempita')

FORCE_EMULATION = False
USE_SSE2 = True if not '--no-sse2' in sys.argv else False

mod_dir = './randomstate'
configs = []

rngs = ['RNG_DSFMT', 'RNG_MLFG_1279_861', 'RNG_MRG32K3A', 'RNG_MT19937',
        'RNG_PCG32', 'RNG_PCG64', 'RNG_XORSHIFT128', 'RNG_XOROSHIRO128PLUS',
        'RNG_XORSHIFT1024', 'RNG_SFMT']

compile_rngs = rngs[:]

extra_defs = [('_CRT_SECURE_NO_WARNINGS', '1')] if os.name == 'nt' else []
extra_defs += [('CYTHON_TRACE_NOGIL','1')] if CYTHON_COVERAGE else []

extra_link_args = ['/LTCG', '/OPT:REF', 'Advapi32.lib', 'Kernel32.lib'] if os.name == 'nt' else []
# TODO: The unddefine is to handle a problem when building
# TODO: manylinux1 on CentOS 5/GCC 4.8.2
base_extra_compile_args = [] if os.name == 'nt' else ['-std=c99', '-U__GNUC_GNU_INLINE__']

if USE_SSE2:
    if os.name == 'nt':
        base_extra_compile_args += ['/wd4146', '/GL']
        if struct.calcsize('P') < 8:
            base_extra_compile_args += ['/arch:SSE2']
    else:
        base_extra_compile_args += ['-msse2']

def write_config(file_name, config):
    flags = config['flags']
    with open(file_name, 'w') as config:
        config.write('# Autogenerated\n\n')
        for key in flags:
            val = flags[key]
            if isinstance(flags[key], str):
                val = '"' + val + '"'
            config.write('DEF ' + key + ' = ' + str(val) + '\n')

base_include_dirs = [mod_dir] + [numpy.get_include()]
if os.name == 'nt' and sys.version_info < (3, 5):
    base_include_dirs += [join(mod_dir, 'src', 'common')]

for rng in rngs:
    if rng not in compile_rngs:
        continue

    file_name = rng.lower().replace('rng_', '')
    flags = {'RS_RNG_MOD_NAME': file_name}
    sources = [join(mod_dir, file_name + '.pyx'),
               join(mod_dir, 'src', 'common', 'entropy.c'),
               join(mod_dir, 'distributions.c'),
               join(mod_dir, 'aligned_malloc.c')]
    include_dirs = base_include_dirs[:]
    extra_compile_args = base_extra_compile_args[:]

    if rng == 'RNG_PCG32':
        sources += [join(mod_dir, 'src', 'pcg', 'pcg32.c')]
        sources += [join(mod_dir, 'interface/pcg-32', 'pcg-32-shim.c')]

        defs = [('RS_PCG32', '1')]

        include_dirs += [join(mod_dir, 'src', 'pcg')]

    elif rng == 'RNG_PCG64':
        sources += [join(mod_dir, 'src', 'pcg64-compat', p) for p in ('pcg64.c',)]
        sources += [join(mod_dir, 'interface/pcg-64', 'pcg-64-shim.c')]

        defs = [('RS_PCG64', '1')]
        flags['RS_PCG128_EMULATED'] = 0
        if sys.maxsize < 2 ** 32 or os.name == 'nt' or FORCE_EMULATION:
            # Force emulated mode here
            defs += [('PCG_FORCE_EMULATED_128BIT_MATH', '1')]
            flags['RS_PCG128_EMULATED'] = 1
        else:
            # TODO: This isn't really right - should test for this and only
            # TODO: use this path if the compiler defines this. For now, an assumption.
            defs += [('__SIZEOF_INT128__', '16')]

        include_dirs += [join(mod_dir, 'src', 'pcg')]

    elif rng == 'RNG_MT19937':
        sources += [join(mod_dir, 'src', 'random-kit', p) for p in ('random-kit.c','random-kit-jump.c')]
        sources += [join(mod_dir, 'interface', 'random-kit', 'random-kit-shim.c')]

        defs = [('RS_RANDOMKIT', '1')]

        include_dirs += [join(mod_dir, 'src', 'random-kit')]

    elif rng == 'RNG_XORSHIFT128':
        sources += [join(mod_dir, 'src', 'xorshift128', 'xorshift128.c')]
        sources += [join(mod_dir, 'interface', 'xorshift128', 'xorshift128-shim.c')]

        defs = [('RS_XORSHIFT128', '1')]

        include_dirs += [join(mod_dir, 'src', 'xorshift128')]
    elif rng == 'RNG_XORSHIFT1024':
        sources += [join(mod_dir, 'src', 'xorshift1024', 'xorshift1024.c')]
        sources += [join(mod_dir, 'interface', 'xorshift1024', 'xorshift1024-shim.c')]

        defs = [('RS_XORSHIFT1024', '1')]

        include_dirs += [join(mod_dir, 'src', 'xorshift1024')]
    elif rng == 'RNG_XOROSHIRO128PLUS':
        sources += [join(mod_dir, 'src', 'xoroshiro128plus', 'xoroshiro128plus.c')]
        sources += [join(mod_dir, 'interface', 'xoroshiro128plus', 'xoroshiro128plus-shim.c')]

        defs = [('RS_XOROSHIRO128PLUS', '1')]

        include_dirs += [join(mod_dir, 'src', 'xoroshiro128plus')]
    elif rng == 'RNG_MRG32K3A':
        sources += [join(mod_dir, 'src', 'mrg32k3a', 'mrg32k3a.c')]
        sources += [join(mod_dir, 'interface', 'mrg32k3a', 'mrg32k3a-shim.c')]

        defs = [('RS_MRG32K3A', '1')]

        include_dirs += [join(mod_dir, 'src', 'mrg32k3a')]

    elif rng == 'RNG_MLFG_1279_861':
        sources += [join(mod_dir, 'src', 'mlfg-1279-861', 'mlfg-1279-861.c')]
        sources += [join(mod_dir, 'interface', 'mlfg-1279-861', 'mlfg-1279-861-shim.c')]

        defs = [('RS_MLFG_1279_861', '1')]

        include_dirs += [join(mod_dir, 'src', 'mlfg_1279_861')]

    elif rng == 'RNG_DSFMT':
        sources += [join(mod_dir, 'src', 'dSFMT', 'dSFMT.c')]
        sources += [join(mod_dir, 'src', 'dSFMT', 'dSFMT-jump.c')]
        sources += [join(mod_dir, 'interface', 'dSFMT', 'dSFMT-shim.c')]
        # TODO: HAVE_SSE2 should only be for platforms that have SSE2
        defs = [('RS_DSFMT', '1'), ('DSFMT_MEXP', '19937')]
        if USE_SSE2:
            defs += [('HAVE_SSE2', '1')]

        include_dirs += [join(mod_dir, 'src', 'dSFMT')]
    elif rng == 'RNG_SFMT':
        sources += [join(mod_dir, 'src', 'sfmt', 'sfmt.c')]
        sources += [join(mod_dir, 'src', 'sfmt', 'sfmt-jump.c')]
        sources += [join(mod_dir, 'interface', 'sfmt', 'sfmt-shim.c')]
        # TODO: HAVE_SSE2 should only be for platforms that have SSE2
        defs = [('RS_SFMT', '1'), ('SFMT_MEXP', '19937')]
        if USE_SSE2:
            defs += [('HAVE_SSE2', '1')]

        include_dirs += [join(mod_dir, 'src', 'sfmt')]

    config = {'file_name': file_name,
              'sources': sources,
              'include_dirs': include_dirs,
              'defs': defs,
              'flags': dict([(k, v) for k, v in flags.items()]),
              'compile_args': extra_compile_args
              }

    configs.append(config)

class BinaryDistribution(Distribution):
    def is_pure(self):
        return False

try:
    import os

    readme_orig_time = os.path.getmtime('README.md')
    readme_mod_time = os.path.getmtime('README.rst')
    if readme_orig_time > readme_mod_time:
        subprocess.call(['pandoc', '--from=markdown', '--to=rst', '--output=README.rst', 'README.md'])
except:
    pass
# Generate files and extensions
extensions = [Extension('randomstate.entropy',
                        sources=[join(mod_dir, 'entropy.pyx'),
                                 join(mod_dir, 'src', 'common', 'entropy.c')],
                        include_dirs=base_include_dirs,
                        define_macros=extra_defs,
                        extra_compile_args=base_extra_compile_args,
                        extra_link_args=extra_link_args)]

for config in configs:
    config_file_name = mod_dir + '/' + config['file_name'] + '-config.pxi'
    # Rewrite core_rng to replace generic #include "config.pxi"
    with open(join(mod_dir, 'randomstate.pyx'), 'r') as original:
        with open(join(mod_dir, config['file_name'] + '.pyx'), 'w') as mod:
            for line in original:
                if line.strip() == 'include "config.pxi"':
                    line = 'include "' + config_file_name + '"\n'
                mod.write(line)
    shutil.copystat(join(mod_dir, 'randomstate.pyx'), join(mod_dir, config['file_name'] + '.pyx'))
    # Write specific config file
    write_config(config_file_name, config)
    shutil.copystat(join(mod_dir, 'randomstate.pyx'), config_file_name)

    ext = Extension(name='randomstate.prng.' + config['file_name'] + '.' + config['file_name'],
                    sources=config['sources'],
                    include_dirs=config['include_dirs'],
                    define_macros=config['defs'] + extra_defs,
                    extra_compile_args=config['compile_args'],
                    extra_link_args=extra_link_args)
    extensions.append(ext)

# Do not run cythonize if clean
if 'clean' in sys.argv:
    def cythonize(e, *args, **kwargs):
        return e
else:
    files = glob.glob('./randomstate/*.in')
    for templated_file in files:
        output_file_name = os.path.splitext(templated_file)[0]
        if (DEVELOP and os.path.exists(output_file_name) and
                (os.path.getmtime(templated_file) < os.path.getmtime(output_file_name))):
            continue
        with open(templated_file, 'r') as source_file:
            template = tempita.Template(source_file.read())
        with open(output_file_name, 'w') as output_file:
            output_file.write(template.substitute())

directives = {'linetrace': CYTHON_COVERAGE}
ext_modules = cythonize(extensions, force=not DEVELOP, annotate=True,
                        compiler_directives=directives)

classifiers = ['Development Status :: 5 - Production/Stable',
               'Environment :: Console',
               'Intended Audience :: End Users/Desktop',
               'Intended Audience :: Financial and Insurance Industry',
               'Intended Audience :: Information Technology',
               'Intended Audience :: Science/Research',
               'License :: OSI Approved',
               'Operating System :: MacOS :: MacOS X',
               'Operating System :: Microsoft :: Windows',
               'Operating System :: POSIX :: Linux',
               'Operating System :: Unix',
               'Programming Language :: C',
               'Programming Language :: Cython',
               'Programming Language :: Python :: 2.7',
               'Programming Language :: Python :: 3.3',
               'Programming Language :: Python :: 3.4',
               'Programming Language :: Python :: 3.5',
               'Programming Language :: Python :: 3.6',
               'Topic :: Adaptive Technologies',
               'Topic :: Artistic Software',
               'Topic :: Office/Business :: Financial',
               'Topic :: Scientific/Engineering',
               'Topic :: Security :: Cryptography']

setup(name='randomstate',
      version=versioneer.get_version(),
      cmdclass=versioneer.get_cmdclass(),
      classifiers=classifiers,
      packages=find_packages(),
      package_dir={'randomstate': './randomstate'},
      package_data={'': ['*.c', '*.h', '*.pxi', '*.pyx', '*.pxd'],
                    'randomstate.tests.data': ['*.csv']},
      include_package_data=True,
      license='NSCA',
      author='Kevin Sheppard',
      author_email='kevin.k.sheppard@gmail.com',
      distclass=BinaryDistribution,
      description='Next-gen RandomState supporting multiple PRNGs',
      url='https://github.com/bashtage/ng-numpy-randomstate',
      long_description=open('README.rst').read(),
      ext_modules=ext_modules,
      keywords=['pseudo random numbers', 'PRNG', 'RNG', 'RandomState', 'random', 'random numbers',
                'parallel random numbers', 'PCG', 'XorShift', 'dSFMT', 'MT19937'],
      zip_safe=False)

# Clean up generated files
# exts = ('.pyx', '-config.pxi', '.c'),
# for config in configs:
#    for ext in exts:
#        file_path = join(mod_dir, config['file_name'] + ext)
#        if os.path.exists(file_path):
#            os.unlink(file_path)

max_stars_repo_name: bashtage/ng-numpy-randomstate

max_issues_repo_name: bashtage/pcg-python

max_forks_repo_name: bashtage/ng-numpy-randomstate


text:
# -*- coding: utf-8 -*-
"""
Created on Fri Oct 26 14:48:54 2018

@author: Administrator
"""

import tensorflow as tf
import numpy as np

class TextCNN(object):
    """
    A RNN for text classification/regression.
    Uses an embedding layer, followed by a recurrent, fully-connected (and softmax) layer.
    """
    def __init__(
            self,model_type,sequence_length,num_classes,vocab_size,
            embedding_size,filter_sizes,num_filters,l2_reg_lambda=0):

        self.input_x = tf.placeholder(tf.int32,[None,sequence_length],name="input_x")
        self.input_y = tf.placeholder(tf.float32,[None,num_classes],name="input_y")
        self.dropout_keep_prob = tf.placeholder(tf.float32,name="dropout_keep_prob")
        self.learing_rate = tf.placeholder(tf.float32,name="learing_rate")

        l2_loss = tf.constant(0.0)

        with tf.device('/cpu:0'),tf.name_scope("embedding"):
            self.W = tf.Variable(tf.random_uniform([vocab_size,embedding_size],-1,1),name="W",trainable=True)
            self.embedded_chars = tf.nn.embedding_lookup(self.W,self.input_x)
            self.embedded_chars_expanded = tf.expand_dims(self.embedded_chars,-1)

        pooled_outputs = []
        for i,filter_size in enumerate(filter_sizes):
            with tf.name_scope("conv-maxpool-%s"%filter_size):
                filter_shape = [filter_size,embedding_size,1,num_filters]
                W = tf.Variable(tf.truncated_normal(filter_shape,stddev=0.1),name="W")
                b = tf.Variable(tf.constant(0.1,shape=[num_filters]),name="b")
                conv = tf.nn.conv2d(self.embedded_chars_expanded,W,strides=[1,1,1,1],padding="VALID",name="conv")
                h = tf.nn.relu(tf.nn.bias_add(conv,b),name="relu")
                pooled = tf.nn.max_pool(h,ksize=[1,sequence_length-filter_size+1,1,1],strides=[1,1,1,1],padding='VALID',name="pool")
                pooled_outputs.append(pooled)

        num_filters_total = num_filters*len(filter_sizes)
        self.h_pool = tf.concat(pooled_outputs,3)
        self.h_pool_flat = tf.reshape(self.h_pool,[-1,num_filters_total])

        with tf.name_scope("dropout"):
            self.h_drop = tf.nn.dropout(self.h_pool_flat,self.dropout_keep_prob)

        with tf.name_scope("output"):
            W = tf.get_variable("W",shape=[num_filters_total,num_classes],initializer=tf.contrib.layers.xavier_initializer())
            b = tf.Variable(tf.constant(0.1,shape=[num_classes]),name="b")
            l2_loss += tf.nn.l2_loss(W)
            l2_loss += tf.nn.l2_loss(b)
            self.scores = tf.nn.xw_plus_b(self.h_drop,W,b,name="scores")
            if(model_type == "clf"):
                self.predictions = tf.argmax(self.scores,1,name="predictions")
            elif model_type=="reg":
                self.predictions = tf.reduce_max(self.scores,1,name="predictions")
                self.predictions = tf.expand_dims(self.predictions,-1)

        with tf.name_scope("loss"):
            if model_type == "clf":
                losses = tf.nn.softmax_cross_entropy_with_logits(logits=self.scores,labels=self.input_y)
                self.loss = tf.reduce_mean(losses)+l2_reg_lambda*l2_loss
            if model_type == "reg":
                losses = tf.sqrt(tf.losses.mean_squared_error(predictions=self.predictions,labels=self.input_y))
                self.loss = tf.reduce_mean(losses)+l2_reg_lambda*l2_loss

        with tf.name_scope("accuracy"):
            if model_type == "clf":
                correct_predictions = tf.equal(self.predictions,tf.argmax(self.input_y,1))
                self.accuracy = tf.reduce_mean(tf.cast(correct_predictions,"float"),name="accuracy")
            elif model_type =="reg":
                self.accuracy = tf.constant(0.0,name="accuracy")


text:
import dataclasses
import datetime
import gzip
import json
import logging
import os
from typing import Any, Dict

import numpy as np
import tensorflow as tf
from absl import flags
from loganary.ranking.common import NumpyJsonEncoder, setup_logging, setup_seed
from loganary.ranking.model import (
    RankingModel,
    RankingModelConfig,
    RankingModelEmbeddingField,
    RankingModelField,
)

flags.DEFINE_string("train_path", None, "Path of .tfrecords file for training.")
flags.DEFINE_string("eval_path", None, "Path of .tfrecords file for evaluation.")
flags.DEFINE_string("keyword_path", None, "Path of vocabulary file for keyword field.")
flags.DEFINE_string("title_path", None, "Path of vocabulary file for title field.")
flags.DEFINE_string("model_path", None, "Path of trained model files.")
flags.DEFINE_integer("num_train_steps", 15000, "The number of train steps.")
flags.DEFINE_list("hidden_layer_dims", ["64", "32", "16"], "Sizes for hidden layers.")
flags.DEFINE_integer(
    "keyword_embedding_dim", 20, "Dimention of an embedding for keyword field."
)
flags.DEFINE_integer(
    "title_embedding_dim", 20, "Dimention of an embedding for title field."
)
flags.DEFINE_integer("batch_size", 32, "Batch size.")
flags.DEFINE_integer("list_size", 100, "List size.")
flags.DEFINE_float("learning_rate", 0.05, "Learning rate.")
flags.DEFINE_integer("group_size", 10, "Group size.")
flags.DEFINE_float("dropout_rate", 0.8, "Dropout rate.")
flags.DEFINE_bool("verbose", False, "Set a logging level as debug.")

FLAGS = flags.FLAGS
logger = logging.getLogger(__name__)

def main(_) -> None:
    setup_seed()
    setup_logging(FLAGS.verbose)

    now_str = datetime.datetime.now().strftime("%Y%m%d%H%M")
    model_path: str = f"{FLAGS.model_path}/{now_str}"
    config: RankingModelConfig = RankingModelConfig(
        model_path=model_path,
        train_path=FLAGS.train_path,
        eval_path=FLAGS.eval_path,
        context_fields=[
            RankingModelEmbeddingField(
                name="keyword",
                vocabulary_file=FLAGS.keyword_path,
                dimension=FLAGS.keyword_embedding_dim,
            ),
        ],
        example_fields=[
            RankingModelEmbeddingField(
                name="title",
                vocabulary_file=FLAGS.title_path,
                dimension=FLAGS.title_embedding_dim,
            ),
        ],
        label_field=RankingModelField(
            name="relevance",
            column_type="numeric",
            default_value=-1,
        ),
        num_train_steps=FLAGS.num_train_steps,
        hidden_layer_dims=FLAGS.hidden_layer_dims,
        batch_size=FLAGS.batch_size,
        list_size=FLAGS.list_size,
        learning_rate=FLAGS.learning_rate,
        group_size=FLAGS.group_size,
        dropout_rate=FLAGS.dropout_rate,
    )
    logger.info(f"Config: {config}")
    model: RankingModel = RankingModel(config)
    result = model.train()
    logger.info(f"Result: {result}")
    export_model_path: str = model.save_model()
    saved_model_path: str = f"{model_path}/saved_model"
    os.rename(export_model_path, saved_model_path)
    logger.info(f"Output Model Path: {saved_model_path}")

    with gzip.open(f"{model_path}/result.json.gz", mode="wt", encoding="utf-8") as f:
        config_dict: Dict[str, Any] = dataclasses.asdict(config)
        del config_dict["eval_metric"]
        f.write(
            json.dumps(
                {
                    "config": config_dict,
                    "result": result,
                },
                ensure_ascii=False,
                cls=NumpyJsonEncoder,
            )
        )

if __name__ == "__main__":
    flags.mark_flag_as_required("train_path")
    flags.mark_flag_as_required("eval_path")
    flags.mark_flag_as_required("keyword_path")
    flags.mark_flag_as_required("title_path")
    flags.mark_flag_as_required("model_path")

    tf.compat.v1.app.run()

max_stars_repo_name: codelibs/logana

max_issues_repo_name: codelibs/logana

max_forks_repo_name: codelibs/logana


text:
# Copyright 2019 Miguel Angel Abella Gonzalez <miguel.abella@udc.es>
#
# 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 required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

"""<replace_with_module_description>"""

from benchmarks.polybench import PolyBench
from benchmarks.polybench_classes import ArrayImplementation
from benchmarks.polybench_classes import PolyBenchOptions, PolyBenchSpec
from numpy.core.multiarray import ndarray

class Mvt(PolyBench):

    def __new__(cls, options: PolyBenchOptions, parameters: PolyBenchSpec):
        implementation = options.POLYBENCH_ARRAY_IMPLEMENTATION
        if implementation == ArrayImplementation.LIST:
            return _StrategyList.__new__(_StrategyList, options, parameters)
        elif implementation == ArrayImplementation.LIST_FLATTENED:
            return _StrategyListFlattened.__new__(_StrategyListFlattened, options, parameters)
        elif implementation == ArrayImplementation.NUMPY:
            return _StrategyNumPy.__new__(_StrategyNumPy, options, parameters)

    def __init__(self, options: PolyBenchOptions, parameters: PolyBenchSpec):
        super().__init__(options, parameters)

        # The parameters hold the necessary information obtained from "polybench.spec" file
        params = parameters.DataSets.get(self.DATASET_SIZE)
        if not isinstance(params, dict):
            raise NotImplementedError(f'Dataset size "{self.DATASET_SIZE.name}" not implemented '
                                      f'for {parameters.Category}/{parameters.Name}.')

        # Set up problem size from the given parameters (adapt this part with appropriate parameters)
        self.N = params.get('N')

    def print_array_custom(self, array: list, name: str):
        # Although two arrays will be printed, they share the same format, so there is no need to check which one comes.
        for i in range(0, self.N):
            if i % 20 == 0:
                self.print_message('\n')
            self.print_value(array[i])

    def run_benchmark(self):
        # Create data structures (arrays, auxiliary variables, etc.)
        A = self.create_array(2, [self.N, self.N], self.DATA_TYPE(0))
        x1 = self.create_array(1, [self.N], self.DATA_TYPE(0))
        x2 = self.create_array(1, [self.N], self.DATA_TYPE(0))
        y_1 = self.create_array(1, [self.N], self.DATA_TYPE(0))
        y_2 = self.create_array(1, [self.N], self.DATA_TYPE(0))

        # Initialize data structures
        self.initialize_array(x1, x2, y_1, y_2, A)

        # Benchmark the kernel
        self.time_kernel(x1, x2, y_1, y_2, A)

        # Return printable data as a list of tuples ('name', value).
        # Each tuple element must have the following format:
        #   (A: str, B: matrix)
        #     - A: a representative name for the data (this string will be printed out)
        #     - B: the actual data structure holding the computed result
        #
        # The syntax for the return statement would then be:
        #   - For single data structure results:
        #     return [('data_name', data)]
        #   - For multiple data structure results:
        #     return [('matrix1', m1), ('matrix2', m2), ... ]
        return [('x1', x1), ('x2', x2)]

class _StrategyList(Mvt):

    def __new__(cls, options: PolyBenchOptions, parameters: PolyBenchSpec):
        return object.__new__(_StrategyList)

    def __init__(self, options: PolyBenchOptions, parameters: PolyBenchSpec):
        super().__init__(options, parameters)

    def initialize_array(self, x1: list, x2: list, y_1: list, y_2: list, A: list):
        for i in range(0, self.N):
            x1[i] = self.DATA_TYPE(i % self.N) / self.N
            x2[i] = self.DATA_TYPE((i + 1) % self.N) / self.N
            y_1[i] = self.DATA_TYPE((i + 3) % self.N) / self.N
            y_2[i] = self.DATA_TYPE((i + 4) % self.N) / self.N
            for j in range(0, self.N):
                A[i][j] = self.DATA_TYPE(i * j % self.N) / self.N

    def kernel(self, x1: list, x2: list, y_1: list, y_2: list, A: list):
# scop begin
        for i in range(0, self.N):
            for j in range(0, self.N):
                x1[i] = x1[i] + A[i][j] * y_1[j]

        for i in range(0, self.N):
            for j in range(0, self.N):
                x2[i] = x2[i] + A[j][i] * y_2[j]
# scop end

class _StrategyListFlattened(Mvt):

    def __new__(cls, options: PolyBenchOptions, parameters: PolyBenchSpec):
        return object.__new__(_StrategyListFlattened)

    def __init__(self, options: PolyBenchOptions, parameters: PolyBenchSpec):
        super().__init__(options, parameters)

    def initialize_array(self, x1: list, x2: list, y_1: list, y_2: list, A: list):
        for i in range(0, self.N):
            x1[i] = self.DATA_TYPE(i % self.N) / self.N
            x2[i] = self.DATA_TYPE((i + 1) % self.N) / self.N
            y_1[i] = self.DATA_TYPE((i + 3) % self.N) / self.N
            y_2[i] = self.DATA_TYPE((i + 4) % self.N) / self.N
            for j in range(0, self.N):
                A[self.N * i + j] = self.DATA_TYPE(i * j % self.N) / self.N

    def kernel(self, x1: list, x2: list, y_1: list, y_2: list, A: list):
# scop begin
        for i in range(0, self.N):
            for j in range(0, self.N):
                x1[i] = x1[i] + A[self.N * i + j] * y_1[j]

        for i in range(0, self.N):
            for j in range(0, self.N):
                x2[i] = x2[i] + A[self.N * j + i] * y_2[j]
# scop end

class _StrategyNumPy(Mvt):

    def __new__(cls, options: PolyBenchOptions, parameters: PolyBenchSpec):
        return object.__new__(_StrategyNumPy)

    def __init__(self, options: PolyBenchOptions, parameters: PolyBenchSpec):
        super().__init__(options, parameters)

    def initialize_array(self, x1: ndarray, x2: ndarray, y_1: ndarray, y_2: ndarray, A: ndarray):
        for i in range(0, self.N):
            x1[i] = self.DATA_TYPE(i % self.N) / self.N
            x2[i] = self.DATA_TYPE((i + 1) % self.N) / self.N
            y_1[i] = self.DATA_TYPE((i + 3) % self.N) / self.N
            y_2[i] = self.DATA_TYPE((i + 4) % self.N) / self.N
            for j in range(0, self.N):
                A[i, j] = self.DATA_TYPE(i * j % self.N) / self.N

    def kernel(self, x1: ndarray, x2: ndarray, y_1: ndarray, y_2: ndarray, A: ndarray):
# scop begin
        for i in range(0, self.N):
            for j in range(0, self.N):
                x1[i] = x1[i] + A[i, j] * y_1[j]

        for i in range(0, self.N):
            for j in range(0, self.N):
                x2[i] = x2[i] + A[j, i] * y_2[j]
# scop end

reason: from numpy


text:
import numpy as np

import ccobra

class RandomModel(ccobra.CCobraModel):
    def __init__(self, name='RandomModel'):
        super(RandomModel, self).__init__(
            name, ['moral'], ['single-choice'])

    def predict(self, item, **kwargs):
        choices = ['PERMISSIBLE','IMPERMISSIBLE']
        prediction = choices[np.random.randint(-1, len(item.choices))]

        return prediction

max_stars_repo_name: monthie/cogmods

max_issues_repo_name: monthie/cogmods

max_forks_repo_name: monthie/cogmods