Skip to content

Instantly share code, notes, and snippets.

@nagachika
nagachika / example.rb
Created September 5, 2020 07:09
mmc question
class Vector
attr_accessor :x, :y, :z
def initialize(x, y, z)
@x = x
@y = y
@z = z
end
def add(v)
Vector.new(self.x+v.x, self.y+v.y, self.z+v.z)
end
@nagachika
nagachika / simple.pbtxt
Created July 17, 2019 06:13
GraphDef pbtxt file for tf-mlir-translate bug reproduction
node {
name: "Const"
op: "Const"
attr {
key: "dtype"
value {
type: DT_INT32
}
}
attr {
@nagachika
nagachika / unbound-method-example.rb
Created May 8, 2019 07:09
UnboundMethod example
module M
def foo
puts "deinfed?(foo) => #{defined?(foo).inspect}"
puts "method(:foo) => #{method(:foo) rescue $!}"
p self
end
end
a = "str-a"
a.extend(M)
class A
DefConst = lambda{|x| Const = x }
def foo(x)
DefConst.call(x)
end
end
p(defined?(A::Const)) # => nil
A.new.foo(42)
@nagachika
nagachika / pitfall.py
Created January 17, 2018 04:39
Pitfall of tf.dataset.Dataset + tf.lookup_ops
# TFRecord のファイルを tf.dataset で読み込むパイプラインを組む
# これは NG
labels = ["a", "b", "c"]
def input_fn():
def _parse_example(example):
features = tf.parse_single_example(example, features=tf_features_dict)
label_str = features.pop("label")
return features, tf.contrib.lookup.index_table_from_tensor(labels).lookup(label_str)
@nagachika
nagachika / CloudLanguageAPIv1SentimentResponseSchemaForBigQuery.json
Last active July 18, 2017 07:20
Cloud Language API v1 Sentiment Response Schema for BigQuery
[
{
"name": "document_sentiment",
"type": "RECORD",
"mode": "NULLABLE",
"fields": [
{
"name": "magnitude",
"type": "FLOAT",
"mode": "NULLABLE"
@nagachika
nagachika / CloudLanguageAPIv1EntitiesResponseSchemaForBigQuery.json
Last active July 18, 2017 10:15
Cloud Language API v1 Entities Response Schema for BigQuery
[
{
"name": "language",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "entities",
"type": "RECORD",
"mode": "REPEATED",
@nagachika
nagachika / Cloud Language API v1 Syntax Response Schema for BigQuery
Last active June 19, 2017 02:17
Cloud Language API v1 Syntax Response Schema for BigQuery
[
{
"name": "language",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "sentences",
"type": "RECORD",
"mode": "REPEATED",
@nagachika
nagachika / google-cloud-speech-api-bigquery-schema.json
Created September 27, 2016 07:40
BigQuery schema for Google Cloud Speech API result
[
{
"name": "results",
"type": "RECORD",
"mode": "REPEATED",
"fields": [
{
"name": "alternatives",
"type": "RECORD",
"mode": "REPEATED",
@nagachika
nagachika / google-cloud-vision-api-bigquery-schema.json
Created September 27, 2016 07:07
BigQuery Schema JSON for Vision API result
[
{
"name": "gcs_url",
"type": "STRING",
"mode": "NULLABLE"
},
{
"name": "timestamp",
"type": "TIMESTAMP",
"mode": "NULLABLE"