Copy disabled (too large)
Download .txt
Showing preview only (74,564K chars total). Download the full file to get everything.
Repository: jiangxinyang227/few_shot_learning
Branch: master
Commit: 19e6d8c1e782
Files: 91
Total size: 71.1 MB
Directory structure:
gitextract_rsk_fl8v/
├── README.md
├── induction_network/
│ ├── config.json
│ ├── data_helper.py
│ ├── metrics.py
│ ├── model.py
│ ├── predict.py
│ └── trainer.py
├── prototypical_network/
│ ├── config.json
│ ├── data_helper.py
│ ├── metrics.py
│ ├── model.py
│ └── trainer.py
├── relation_network/
│ ├── config.json
│ ├── data_helper.py
│ ├── metrics.py
│ ├── model.py
│ └── trainer.py
├── reviews/
│ ├── english
│ ├── eval/
│ │ ├── books.t2
│ │ ├── books.t4
│ │ ├── books.t5
│ │ ├── dvd.t2
│ │ ├── dvd.t4
│ │ ├── dvd.t5
│ │ ├── electronics.t2
│ │ ├── electronics.t4
│ │ ├── electronics.t5
│ │ ├── kitchen_housewares.t2
│ │ ├── kitchen_housewares.t4
│ │ └── kitchen_housewares.t5
│ └── train/
│ ├── apparel.t2
│ ├── apparel.t4
│ ├── apparel.t5
│ ├── automotive.t2
│ ├── automotive.t4
│ ├── automotive.t5
│ ├── baby.t2
│ ├── baby.t4
│ ├── baby.t5
│ ├── beauty.t2
│ ├── beauty.t4
│ ├── beauty.t5
│ ├── camera_photo.t2
│ ├── camera_photo.t4
│ ├── camera_photo.t5
│ ├── cell_phones_service.t2
│ ├── cell_phones_service.t4
│ ├── cell_phones_service.t5
│ ├── computer_video_games.t2
│ ├── computer_video_games.t4
│ ├── computer_video_games.t5
│ ├── gourmet_food.t2
│ ├── gourmet_food.t4
│ ├── gourmet_food.t5
│ ├── grocery.t2
│ ├── grocery.t4
│ ├── grocery.t5
│ ├── health_personal_care.t2
│ ├── health_personal_care.t4
│ ├── health_personal_care.t5
│ ├── jewelry_watches.t2
│ ├── jewelry_watches.t4
│ ├── jewelry_watches.t5
│ ├── magazines.t2
│ ├── magazines.t4
│ ├── magazines.t5
│ ├── music.t2
│ ├── music.t4
│ ├── music.t5
│ ├── office_products.t4
│ ├── office_products.t5
│ ├── outdoor_living.t2
│ ├── outdoor_living.t4
│ ├── outdoor_living.t5
│ ├── software.t2
│ ├── software.t4
│ ├── software.t5
│ ├── sports_outdoors.t2
│ ├── sports_outdoors.t4
│ ├── sports_outdoors.t5
│ ├── toys_games.t2
│ ├── toys_games.t4
│ ├── toys_games.t5
│ ├── video.t2
│ ├── video.t4
│ └── video.t5
└── siamese_network/
├── config.json
├── data_helper.py
├── metrics.py
├── model.py
└── trainer.py
================================================
FILE CONTENTS
================================================
================================================
FILE: README.md
================================================
### few-shot learning
##### Each folder contains an implementation of each model.
* data_helper. data processing
* model. model construction
* trainer. train model
* metrics. performance metrics
* config.json Configuration files for model parameters and training parameters
#### induction_network
* paper: Few-Shot Text Classification with Induction Network
#### relation_network
* paper: Learning to Compare: Relation Network for Few-Shot Learning
#### prototypical_network
* paper: Prototypical Networks for Few-shot Learning
#### siamese_network
* paper: Siamese Neural Networks for One-shot Image Recognition
#### ARSC data set
* the data from Amazon Review Data Set, arranged by Alibaba Group
* citation: ***Image-based recommendations on styles and substitutes J. McAuley, C. Targett, J. Shi, A. van den Hengel SIGIR, 2015***
* citation: ***Mo Yu, Xiaoxiao Guo, Jinfeng Yi, Shiyu Chang, Saloni Potdar, Yu Cheng, Gerald Tesauro, Haoyu Wang, and Bowen Zhou. 2018. Diverse few-shot text classification with multiple metrics***
#### word vector
* using glove word vector, you need download 300 dim glove word vector and place it in word_embedded dir.
#### note
* You can only use 2-way, and if you need to use other way, you can modify the data_helper.py file.
* Shot should not be more than 10, because there are few comments under some categories.
* The number of categories in prediction and training can not be equal.
================================================
FILE: induction_network/config.json
================================================
{
"model_name": "induction",
"epochs": 30,
"checkpoint_every": 500,
"eval_every": 500,
"learning_rate": 1e-3,
"optimization": "adam",
"embedding_size": 300,
"hidden_sizes": [128],
"attention_size": 64,
"layer_size": 100,
"num_support": 5,
"num_queries": 5,
"num_classes": 2,
"num_tasks": 1000,
"num_eval_tasks": 500,
"sequence_length": 100,
"low_freq": 5,
"keep_prob": 0.6,
"l2_reg_lambda": 0.0,
"max_grad_norm": 3.0,
"train_data": "../reviews/train",
"eval_data": "../reviews/eval",
"stop_word_path": "../reviews/english",
"output_path": "output/induction",
"word_vector_path": "../word_embedded/glove.6B.300d.txt",
"ckpt_model_path": "ckpt_model/induction",
"pb_model_path": "pb_model/induction"
}
================================================
FILE: induction_network/data_helper.py
================================================
"""
data process
"""
import os
import json
import random
import copy
from collections import Counter
from itertools import chain
from typing import Dict, Tuple, Optional, List, Union
import gensim
import numpy as np
class InductionData(object):
def __init__(self, output_path: str, sequence_length: int = 100, num_classes: int = 2, num_support: int = 5,
num_queries: int = 50, num_tasks: int = 1000, num_eval_tasks: int = 100,
stop_word_path: Optional[str] = None,
embedding_size: Optional[int] = None, low_freq: int = 5,
word_vector_path: Optional[str] = None, is_training: bool = True):
"""
init method
:param output_path: path of train/eval data
:param num_classes: number of support class
:param num_support: number of support sample per class
:param num_queries: number of query sample per class
:param num_tasks: number of pre-sampling tasks, this will speeding up train
:param num_eval_tasks: number of pre-sampling tasks in eval stage
:param stop_word_path: path of stop word file
:param embedding_size: embedding size
:param low_freq: frequency of words
:param word_vector_path: path of word vector file(eg. word2vec, glove)
:param is_training: bool
"""
self.__output_path = output_path
if not os.path.exists(self.__output_path):
os.makedirs(self.__output_path)
self.__sequence_length = sequence_length
self.__num_classes = num_classes
self.__num_support = num_support
self.__num_queries = num_queries
self.__num_tasks = num_tasks
self.__num_eval_tasks = num_eval_tasks
self.__stop_word_path = stop_word_path
self.__embedding_size = embedding_size
self.__low_freq = low_freq
self.__word_vector_path = word_vector_path
self.__is_training = is_training
self.vocab_size = None
self.word_vectors = None
self.current_category_index = 0 # record current sample category
print("stop word path: ", self.__stop_word_path)
print("word vector path: ", self.__word_vector_path)
@staticmethod
def load_data(data_path: str) -> Dict[str, Dict[str, List[List[str]]]]:
"""
read train/eval data
:param data_path:
:return: dict. {class_name: {sentiment: [[]], }, ...}
"""
category_files = os.listdir(data_path)
categories_data = {}
for category_file in category_files:
file_path = os.path.join(data_path, category_file)
sentiment_data = {}
with open(file_path, "r", encoding="utf8") as fr:
for line in fr.readlines():
content, label = line.strip().split("\t")
if sentiment_data.get(label, None):
sentiment_data[label].append(content.split(" "))
else:
sentiment_data[label] = [content.split(" ")]
print("task name: ", category_file)
print("pos samples length: ", len(sentiment_data["1"]))
print("neg samples length: ", len(sentiment_data["-1"]))
categories_data[category_file] = sentiment_data
return categories_data
def remove_stop_word(self, data: Dict[str, Dict[str, List[List[str]]]]) -> List[str]:
"""
remove low frequency words and stop words, construct vocab
:param data: {class_name: {sentiment: [[]], }, ...}
:return:
"""
all_words = []
for category, category_data in data.items():
for sentiment, sentiment_data in category_data.items():
all_words.extend(list(chain(*sentiment_data)))
word_count = Counter(all_words) # statistic the frequency of words
sort_word_count = sorted(word_count.items(), key=lambda x: x[1], reverse=True)
# remove low frequency word
words = [item[0] for item in sort_word_count if item[1] > self.__low_freq]
# if stop word file exists, then remove stop words
if self.__stop_word_path:
with open(self.__stop_word_path, "r", encoding="utf8") as fr:
stop_words = [line.strip() for line in fr.readlines()]
words = [word for word in words if word not in stop_words]
return words
def get_word_vectors(self, vocab: List[str]) -> np.ndarray:
"""
load word vector file,
:param vocab: vocab
:return:
"""
pad_vector = np.zeros(self.__embedding_size) # set the "<pad>" vector to 0
word_vectors = (1 / np.sqrt(len(vocab) - 1) * (2 * np.random.rand(len(vocab) - 1, self.__embedding_size) - 1))
word_vectors = np.vstack((pad_vector, word_vectors))
# load glove vectors
glove_vector = {}
with open(self.__word_vector_path, "r", encoding="utf8") as fr:
for line in fr.readlines():
line_list = line.strip().split(" ")
glove_vector[line_list[0]] = line_list[1:]
for i in range(1, len(vocab)):
if glove_vector.get(vocab[i], None):
word_vectors[i, :] = glove_vector[vocab[i]]
else:
print(vocab[i] + " not exist word vector file")
# # load gensim word2vec vectors
# if os.path.splitext(self.__word_vector_path)[-1] == ".bin":
# word_vec = gensim.models.KeyedVectors.load_word2vec_format(self.__word_vector_path, binary=True)
# else:
# word_vec = gensim.models.KeyedVectors.load_word2vec_format(self.__word_vector_path)
#
# for i in range(1, len(vocab)):
# try:
# vector = word_vec.wv[vocab[i]]
# word_vectors[i, :] = vector
# except:
# print(vocab[i] + "not exist word vector file")
return word_vectors
def gen_vocab(self, words: List[str]) -> Dict[str, int]:
"""
generate word_to_index mapping table
:param words:
:return:
"""
if self.__is_training:
vocab = ["<pad>", "<unk>"] + words
self.vocab_size = len(vocab)
if self.__word_vector_path:
word_vectors = self.get_word_vectors(vocab)
self.word_vectors = word_vectors
# save word vector to npy file
np.save(os.path.join(self.__output_path, "word_vectors.npy"), self.word_vectors)
word_to_index = dict(zip(vocab, list(range(len(vocab)))))
# save word_to_index to json file
with open(os.path.join(self.__output_path, "word_to_index.json"), "w") as f:
json.dump(word_to_index, f)
else:
with open(os.path.join(self.__output_path, "word_to_index.json"), "r") as f:
word_to_index = json.load(f)
return word_to_index
@staticmethod
def trans_to_index(data: Dict[str, Dict[str, List[List[str]]]], word_to_index: Dict[str, int]) -> \
Dict[str, Dict[str, List[List[int]]]]:
"""
transformer token to id
:param data:
:param word_to_index:
:return: {class_name: [[], [], ], ..}
"""
data_ids = {category: {sentiment: [[word_to_index.get(token, word_to_index["<unk>"]) for token in line]
for line in sentiment_data]
for sentiment, sentiment_data in category_data.items()}
for category, category_data in data.items()}
return data_ids
def choice_support_query(self, task_data: Dict[str, List[List[int]]])\
-> Tuple[List[List[List[int]]], List[List[int]], List[int]]:
"""
randomly selecting support set, query set form a task.
:param task_data: all data for a task
:return:
"""
label_to_index = {"1": 0, "-1": 1}
if self.__is_training:
with open(os.path.join(self.__output_path, "label_to_index.json"), "w") as f:
json.dump(label_to_index, f)
pos_samples = task_data["1"]
neg_samples = task_data["-1"]
pos_support = random.sample(pos_samples, self.__num_support)
neg_support = random.sample(neg_samples, self.__num_support)
pos_others = copy.copy(pos_samples)
[pos_others.remove(data) for data in pos_support]
neg_others = copy.copy(neg_samples)
[neg_others.remove(data) for data in neg_support]
pos_query = random.sample(pos_others, self.__num_queries)
neg_query = random.sample(neg_others, self.__num_queries)
# padding
pos_support = self.padding(pos_support)
neg_support = self.padding(neg_support)
pos_query = self.padding(pos_query)
neg_query = self.padding(neg_query)
support_set = [pos_support, neg_support] # [num_classes, num_support, sequence_length]
query_set = pos_query + neg_query # [num_classes * num_queries, sequence_length]
labels = [label_to_index["1"]] * len(pos_query) + [label_to_index["-1"]] * len(neg_query)
return support_set, query_set, labels
def samples(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
-> List[Dict[str, Union[List[List[List[int]]], List[List[int]], List[int]]]]:
"""
positive and negative sample from raw data
:param data_ids:
:return:
"""
# product name list
category_list = list(data_ids.keys())
tasks = []
if self.__is_training:
num_tasks = self.__num_tasks
else:
num_tasks = self.__num_eval_tasks
for i in range(num_tasks):
# randomly choice a category to construct train sample
support_category = random.choice(category_list)
support_set, query_set, labels = self.choice_support_query(data_ids[support_category])
tasks.append(dict(support=support_set, queries=query_set, labels=labels))
return tasks
def gen_data(self, file_path: str) -> Dict[str, Dict[str, List[List[int]]]]:
"""
Generate data that is eventually input to the model
:return:
"""
# load data
data = self.load_data(file_path)
# remove stop word
words = self.remove_stop_word(data)
word_to_index = self.gen_vocab(words)
data_ids = self.trans_to_index(data, word_to_index)
return data_ids
def padding(self, sentences: List[List[int]]) -> List[List[int]]:
"""
padding according to the predefined sequence length
:param sentences:
:return:
"""
sentence_pad = [sentence[:self.__sequence_length] if len(sentence) > self.__sequence_length
else sentence + [0] * (self.__sequence_length - len(sentence))
for sentence in sentences]
return sentence_pad
def next_batch(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
-> Dict[str, Union[List[List[List[int]]], List[List[int]], List[int]]]:
"""
train a task at every turn
:param data_ids:
:return:
"""
tasks = self.samples(data_ids)
for task in tasks:
yield task
================================================
FILE: induction_network/metrics.py
================================================
"""
performance metrics function
"""
def mean(item: list) -> float:
"""
Calculate the mean of the list
:param item: list object
:return:
"""
res = sum(item) / len(item) if len(item) > 0 else 0
return res
def accuracy(pred_y, true_y):
"""
Calculate accuracy
:param pred_y: predict result
:param true_y: true result
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
corr = 0
for i in range(len(pred_y)):
if pred_y[i] == true_y[i]:
corr += 1
acc = corr / len(pred_y) if len(pred_y) > 0 else 0
return acc
def binary_precision(pred_y, true_y, positive=1):
"""
Calculate the precision of binary classification
:param pred_y: predict result
:param true_y: true result
:param positive: index of positive label
:return:
"""
corr = 0
pred_corr = 0
for i in range(len(pred_y)):
if pred_y[i] == positive:
pred_corr += 1
if pred_y[i] == true_y[i]:
corr += 1
prec = corr / pred_corr if pred_corr > 0 else 0
return prec
def binary_recall(pred_y, true_y, positive=1):
"""
Calculate the recall of binary classification
:param pred_y: predict result
:param true_y: true result
:param positive: index of positive label
:return:
"""
corr = 0
true_corr = 0
for i in range(len(pred_y)):
if true_y[i] == positive:
true_corr += 1
if pred_y[i] == true_y[i]:
corr += 1
rec = corr / true_corr if true_corr > 0 else 0
return rec
def binary_f_beta(pred_y, true_y, beta=1.0, positive=1):
"""
Calculate the f beta of binary classification
:param pred_y: predict result
:param beta: beta parameter
:param true_y: true result
:param positive: index of positive label
:return:
"""
precision = binary_precision(pred_y, true_y, positive)
recall = binary_recall(pred_y, true_y, positive)
try:
f_b = (1 + beta * beta) * precision * recall / (beta * beta * precision + recall)
except:
f_b = 0
return f_b
def get_binary_metrics(pred_y, true_y, f_beta=1.0):
"""
Calculate various performance metrics of binary classification
:param pred_y: predict result
:param true_y: true result
:param f_beta: beta parameter
:return:
"""
acc = accuracy(pred_y, true_y)
recall = binary_recall(pred_y, true_y)
precision = binary_precision(pred_y, true_y)
f_beta = binary_f_beta(pred_y, true_y, f_beta)
return acc, recall, precision, f_beta
def multi_precision(pred_y, true_y, labels):
"""
Calculate the precision of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
precisions = [binary_precision(pred_y, true_y, label) for label in labels]
prec = mean(precisions)
return prec
def multi_recall(pred_y, true_y, labels):
"""
Calculate the recall of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
recalls = [binary_recall(pred_y, true_y, label) for label in labels]
rec = mean(recalls)
return rec
def multi_f_beta(pred_y, true_y, labels, beta=1.0):
"""
Calculate the f value of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:param beta: beta parameter
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
f_betas = [binary_f_beta(pred_y, true_y, beta, label) for label in labels]
f_beta = mean(f_betas)
return f_beta
def get_multi_metrics(pred_y, true_y, labels, f_beta=1.0):
"""
Calculate various performance metrics of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:param beta: beta parameter
:return:
"""
acc = accuracy(pred_y, true_y)
recall = multi_recall(pred_y, true_y, labels)
precision = multi_precision(pred_y, true_y, labels)
f_beta = multi_f_beta(pred_y, true_y, labels, f_beta)
return acc, recall, precision, f_beta
================================================
FILE: induction_network/model.py
================================================
"""
prototypical network model for few shot learning
"""
import tensorflow as tf
class InductionModel(object):
def __init__(self, config, vocab_size, word_vectors):
self.config = config
self.vocab_size = vocab_size
self.word_vectors = word_vectors
self.num_classes = self.config["num_classes"]
# [num_classes, num_support, sequence_length]
self.support = tf.placeholder(tf.int32, [None, None, None], name="support")
# [num_classes * num_queries, sequence_length]
self.queries = tf.placeholder(tf.int32, [None, None], name="queries")
# [num_classes * num_queries]
self.labels = tf.placeholder(tf.int32, [None], name="labels")
self.keep_prob = tf.placeholder(tf.float32, name="keep_prob") # dropout
self.l2_loss = tf.constant(0.0) # l2 regulation
# construct graph
self.model_structure()
# Initialize the object that saves the model
self.init_saver()
def model_structure(self):
# embedding layer
with tf.name_scope("embedding"):
# Initialization of Word Embedding Matrix Using Pre-trained Word Vectors
if self.word_vectors is not None:
embedding_w = tf.Variable(tf.cast(self.word_vectors, dtype=tf.float32, name="word2vec"),
name="embedding_w")
else:
embedding_w = tf.get_variable("embedding_w", shape=[self.vocab_size, self.config["embedding_size"]],
initializer=tf.random_normal_initializer())
# support embedding. dimension: [num_classes, num_support, sequence_length, embedding_size]
support_embedded = tf.nn.embedding_lookup(embedding_w, self.support, name="support_embedded")
# query embedding. dimension: [num_classes * num_queries, sequence_length, embedding_size]
queries_embedded = tf.nn.embedding_lookup(embedding_w, self.queries, name="queries_embedded")
# reshape support set to 3 dimensions. [num_classes * num_support, sequence_length, embedding_size]
support_embedded_reshape = tf.reshape(support_embedded,
[-1, self.config["sequence_length"], self.config["embedding_size"]])
with tf.name_scope("Bi-LSTM"):
for idx, hidden_size in enumerate(self.config["hidden_sizes"]):
with tf.name_scope("Bi-LSTM" + str(idx)):
# frontward lstm cell
lstm_fw_cell = tf.nn.rnn_cell.DropoutWrapper(
tf.nn.rnn_cell.LSTMCell(num_units=hidden_size, initializer=tf.orthogonal_initializer(),
state_is_tuple=True),
output_keep_prob=self.keep_prob)
# backward lstm cell
lstm_bw_cell = tf.nn.rnn_cell.DropoutWrapper(
tf.nn.rnn_cell.LSTMCell(num_units=hidden_size, initializer=tf.orthogonal_initializer(),
state_is_tuple=True),
output_keep_prob=self.keep_prob)
# bi-lstm dynamic decode
support_output, _ = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell, lstm_bw_cell,
support_embedded_reshape,
dtype=tf.float32,
scope="bi-lstm_1" + str(idx))
queries_output, _ = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell, lstm_bw_cell,
queries_embedded,
dtype=tf.float32,
scope="bi-lstm_2" + str(idx))
# concat frontward and backward output of lstm
# [num_classes * num_support, sequence_length, hidden_size * 2]
support_embedded_reshape = tf.concat(support_output, -1)
# [num_classes * num_queries, sequence_length, hidden_size * 2]
queries_embedded = tf.concat(queries_output, -1)
# [num_classes * num_support, hidden_size * 2]
support_final_output = self._attention(support_embedded_reshape, scope_name="support")
# [num_classes * num_queries, hidden_size * 2]
queries_final_output = self._attention(queries_embedded, scope_name="queries")
# induction module be used to generate class vectors
with tf.name_scope("induction_module"):
support_class = self.dynamic_routing(tf.reshape(support_final_output,
[self.num_classes,
self.config["num_support"],
-1]))
with tf.name_scope("relation_module"):
scores = self.neural_tensor_layer(support_class, queries_final_output)
self.scores = scores
self.predictions = tf.argmax(scores, axis=-1, name="predictions")
with tf.name_scope("loss"):
labels_one_hot = tf.one_hot(self.labels, self.num_classes, dtype=tf.float32)
losses = tf.losses.mean_squared_error(labels=labels_one_hot, predictions=scores)
l2_losses = tf.add_n(
[tf.nn.l2_loss(v)
for v in tf.trainable_variables() if 'bias' not in v.name]) * self.config["l2_reg_lambda"]
self.loss = losses + l2_losses
with tf.name_scope("train_op"):
# define optimizer
optimizer = self.get_optimizer()
trainable_params = tf.trainable_variables()
gradients = tf.gradients(self.loss, trainable_params)
# gradient clip
clip_gradients, _ = tf.clip_by_global_norm(gradients, self.config["max_grad_norm"])
self.train_op = optimizer.apply_gradients(zip(clip_gradients, trainable_params))
def dynamic_routing(self, support_encoding, iter_routing=3):
"""
the dynamic routing algorithm
:param support_encoding:
:param iter_routing: number of iterate
:return:
"""
num_classes = self.num_classes
num_support = self.config["num_support"]
encode_size = self.config["hidden_sizes"][-1] * 2
# init dynamic routing values, weights of samples per class. [num_classes, num_support]
init_b = tf.constant(0.0, dtype=tf.float32, shape=[num_classes, num_support])
# transformer matrix, mapping input to another space. [encode_size, encode_size]
w_s = tf.get_variable("w_s", shape=[encode_size, encode_size], dtype=tf.float32,
initializer=tf.glorot_uniform_initializer())
# Iterating to update dynamic routing values
for r_iter in range(iter_routing):
with tf.variable_scope('iter_' + str(r_iter)):
# normalization dynamic routing values. [num_classes, num_support, 1]
norm_b = tf.nn.softmax(tf.reshape(init_b, [num_classes, num_support, 1]), axis=1)
# mapping support to another space. [num_classes, num_support, encoder_size]
support_trans = tf.reshape(tf.matmul(tf.reshape(support_encoding, [-1, encode_size]), w_s),
[num_classes, num_support, encode_size])
# weighted sum. [num_classes, encoder_size]
c_i = tf.reduce_sum(tf.multiply(support_trans, norm_b), axis=1)
# squash activate function
c_squared_norm = tf.reduce_sum(tf.square(c_i), 1, keepdims=True)
scalar_factor = c_squared_norm / (1 + c_squared_norm) / tf.sqrt(c_squared_norm + 1e-9)
c_squashed = scalar_factor * c_i # element-wise
# Calculate the dot between samples and class vectors for per class
c_e_dot = tf.matmul(support_trans, tf.reshape(c_squashed, [num_classes, encode_size, 1]))
# update dynamic routing values
init_b += tf.reshape(c_e_dot, [num_classes, num_support])
return c_squashed
def neural_tensor_layer(self, class_vector, query_encoder):
"""
calculate relation scores
:param class_vector: class vectors
:param query_encoder: query set encoding matrix. [num_classes * num_queries, encode_size]
:return:
"""
num_classes = self.num_classes
encode_size = self.config["hidden_sizes"][-1] * 2
layer_size = self.config["layer_size"]
M = tf.get_variable("M", [encode_size, encode_size, layer_size], dtype=tf.float32,
initializer=tf.truncated_normal_initializer(stddev=(2 / encode_size) ** 0.5))
# 该层可以理解为从不同的视角去计算类向量和query向量的分数
# [[class1, class2, ..], [class1, class2, ..], ... layer_size]
all_mid = []
for i in range(layer_size):
# [num_classes, num_classes * num_queries]
slice_mid = tf.matmul(tf.matmul(class_vector, M[:, :, i]), query_encoder, transpose_b=True)
all_mid.append(tf.split(slice_mid, [1] * num_classes, axis=0))
# [[1, 2, .. layer_size], ... class_n], 将同一个类经tensor layer计算出来的分数放在一起
all_mid = [[mid[j] for mid in all_mid] for j in range(len(all_mid[0]))]
# [layer_size, num_classes * num_queries]
all_mid_concat = [tf.concat(mid, axis=0) for mid in all_mid]
# [num_classes * num_queries, layer_size]
all_mid_transpose = [tf.nn.relu(tf.transpose(mid)) for mid in all_mid_concat]
relation_w = tf.get_variable("relation_w", [layer_size, 1], dtype=tf.float32,
initializer=tf.glorot_normal_initializer())
relation_b = tf.get_variable("relation_b", [1], dtype=tf.float32,
initializer=tf.glorot_normal_initializer())
scores = []
for mid in all_mid_transpose:
score = tf.nn.sigmoid(tf.matmul(mid, relation_w) + relation_b)
scores.append(score)
# [num_classes * num_queries, num_classes]
scores = tf.concat(scores, axis=-1)
return scores
def _attention(self, H, scope_name):
"""
attention for the final output of Lstm
:param H: [batch_size, sequence_length, hidden_size * 2]
"""
with tf.variable_scope(scope_name):
hidden_size = self.config["hidden_sizes"][-1] * 2
attention_size = self.config["attention_size"]
w_1 = tf.get_variable("w_1", shape=[hidden_size, attention_size],
initializer=tf.glorot_normal_initializer)
w_2 = tf.Variable(tf.random_normal([attention_size], stddev=0.1))
# Nonlinear conversion for LSTM output, [batch_size * sequence_length, attention_size]
M = tf.tanh(tf.matmul(tf.reshape(H, [-1, hidden_size]), w_1))
# calculate weights, [batch_size, sequence_length]
weights = tf.reshape(tf.matmul(M, tf.reshape(w_2, [-1, 1])),
[-1, self.config["sequence_length"]])
# softmax normalization, [batch_size, sequence_length]
alpha = tf.nn.softmax(weights, axis=-1)
# calculate weighted sum
output = tf.reduce_sum(H * tf.reshape(alpha, [-1, self.config["sequence_length"], 1]), axis=1)
return output
def get_optimizer(self):
"""
define optimizer
:return:
"""
optimizer = None
if self.config["optimization"] == "adam":
optimizer = tf.train.AdamOptimizer(self.config["learning_rate"])
if self.config["optimization"] == "rmsprop":
optimizer = tf.train.RMSPropOptimizer(self.config["learning_rate"])
if self.config["optimization"] == "sgd":
optimizer = tf.train.GradientDescentOptimizer(self.config["learning_rate"])
return optimizer
def init_saver(self):
"""
init model saver object
:return:
"""
self.saver = tf.train.Saver(tf.global_variables())
def train(self, sess, batch, dropout_prob):
"""
train model method
:param sess: session object of tensorflow
:param batch: train batch data
:param dropout_prob: dropout keep prob
:return: loss, predict result
"""
feed_dict = {self.support: batch["support"],
self.queries: batch["queries"],
self.labels: batch["labels"],
self.keep_prob: dropout_prob}
# 训练模型
_, loss, predictions = sess.run([self.train_op, self.loss, self.predictions],
feed_dict=feed_dict)
return loss, predictions
def eval(self, sess, batch):
"""
evaluate model method
:param sess: session object of tensorflow
:param batch: eval batch data
:return: loss, predict result
"""
feed_dict = {self.support: batch["support"],
self.queries: batch["queries"],
self.labels: batch["labels"],
self.keep_prob: 1.0}
loss, predictions = sess.run([self.loss, self.predictions], feed_dict=feed_dict)
return loss, predictions
def infer(self, sess, batch):
"""
infer model method
:param sess:
:param batch:
:return: predict result
"""
feed_dict = {self.support: batch["support"],
self.queries: batch["queries"],
self.keep_prob: 1.0}
predict, scores = sess.run([self.predictions, self.scores], feed_dict=feed_dict)
return predict, scores
================================================
FILE: induction_network/predict.py
================================================
#!/usr/bin/env python
# -*- coding:utf-8 -*-
"""
-------------------------------------------------
File Name : predict.py
Author : 王枫
date : 2019/11/13 18:13
-------------------------------------------------
Description :
-------------------------------------------------
"""
import json
import os
import tensorflow as tf
from model import InductionModel
import numpy as np
def online_predict():
with open("config.json", "r") as fr:
config = json.load(fr)
with open("output/induction/word_to_index.json", "r") as f:
word2id = json.load(f)
word_vectors = np.load("output/induction/word_vectors.npy")
config["num_classes"] = 3
model = InductionModel(config=config, vocab_size=len(word2id), word_vectors=word_vectors)
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.9, allow_growth=True)
sess_config = tf.ConfigProto(log_device_placement=False, allow_soft_placement=True, gpu_options=gpu_options)
max_lens = config["sequence_length"]
with tf.Session(config=sess_config) as sess:
save_path = os.path.join(os.path.abspath(os.getcwd()), config["ckpt_model_path"])
checkpoint_prefix = os.path.join(save_path, config["model_name"] + "-500")
model.saver.restore(sess, checkpoint_prefix)
pos_sentence = ["i like it", "i love it", "i get it make me so happy", "happy", "so love it"]
neu_sentence = ["hello world", "hello python", "what is it", "are you ok", "hello c++"]
neg_sentence = ["it's do bad", "rubbish", "i don't like it", "i don't love it", "shit"]
pos_ids = []
for sentence in pos_sentence:
ids = [word2id[word] if word in word2id else 1 for word in sentence.split(" ")]
if len(ids) < max_lens:
ids = ids + [0] * (max_lens - len(ids))
ids = ids[:max_lens]
pos_ids.append(ids)
neg_ids = []
for sentence in neg_sentence:
ids = [word2id[word] if word in word2id else 1 for word in sentence.split(" ")]
if len(ids) < max_lens:
ids = ids + [0] * (max_lens - len(ids))
ids = ids[:max_lens]
neg_ids.append(ids)
neu_ids = []
for sentence in neu_sentence:
ids = [word2id[word] if word in word2id else 1 for word in sentence.split(" ")]
if len(ids) < max_lens:
ids = ids + [0] * (max_lens - len(ids))
ids = ids[:max_lens]
neu_ids.append(ids)
support = [pos_ids, neu_ids, neg_ids]
while True:
queries = []
for i in range(1):
sentence = input("输入测试句子:")
ids = [word2id[word] if word in word2id else 1 for word in sentence.split(" ")]
if len(ids) < max_lens:
ids = ids + [0] * (max_lens - len(ids))
ids = ids[:max_lens]
queries.append(ids)
batch1 = {"queries": queries, "support": support}
predict, scores = model.infer(sess, batch1)
print("===============================")
print(predict, scores)
if __name__ == "__main__":
online_predict()
================================================
FILE: induction_network/trainer.py
================================================
import argparse
import json
import os
import tensorflow as tf
from data_helper import InductionData
from metrics import get_multi_metrics, mean
from model import InductionModel
class InductionTrainer(object):
def __init__(self, args):
self.args = args
with open(args.config_path, "r") as fr:
self.config = json.load(fr)
# self.builder = tf.saved_model.builder.SavedModelBuilder("../pb_model/weibo/bilstm/savedModel")
# load date set
self.train_data_obj = self.load_data()
self.eval_data_obj = self.load_data(is_training=False)
self.train_data = self.train_data_obj.gen_data(self.config["train_data"])
self.eval_data = self.eval_data_obj.gen_data(self.config["eval_data"])
print("vocab size: ", self.train_data_obj.vocab_size)
self.model = self.create_model()
def load_data(self, is_training=True):
"""
init data object
:return:
"""
data_obj = InductionData(output_path=self.config["output_path"],
sequence_length=self.config["sequence_length"],
num_classes=self.config["num_classes"],
num_support=self.config["num_support"],
num_queries=self.config["num_queries"],
num_tasks=self.config["num_tasks"],
num_eval_tasks=self.config["num_eval_tasks"],
embedding_size=self.config["embedding_size"],
stop_word_path=self.config["stop_word_path"],
word_vector_path=self.config["word_vector_path"],
is_training=is_training)
return data_obj
def create_model(self):
"""
init model object
:return:
"""
model = InductionModel(config=self.config, vocab_size=self.train_data_obj.vocab_size,
word_vectors=self.train_data_obj.word_vectors)
return model
def train(self):
"""
train model
:return:
"""
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.9, allow_growth=True)
sess_config = tf.ConfigProto(log_device_placement=False, allow_soft_placement=True, gpu_options=gpu_options)
with tf.Session(config=sess_config) as sess:
# init all variable in graph
sess.run(tf.global_variables_initializer())
current_step = 0
for epoch in range(self.config["epochs"]):
print("----- Epoch {}/{} -----".format(epoch + 1, self.config["epochs"]))
for batch in self.train_data_obj.next_batch(self.train_data):
loss, predictions = self.model.train(sess, batch, self.config["keep_prob"])
label_list = list(set(batch["labels"]))
acc, recall, prec, f_beta = get_multi_metrics(pred_y=predictions, true_y=batch["labels"],
labels=label_list)
print("train: step: {}, loss: {}, acc: {}, recall: {}, precision: {}, f_beta: {}".format(
current_step, loss, acc, recall, prec, f_beta))
current_step += 1
if current_step % self.config["checkpoint_every"] == 0:
eval_losses = []
eval_accs = []
eval_recalls = []
eval_precs = []
eval_f_betas = []
for eval_batch in self.eval_data_obj.next_batch(self.eval_data):
eval_loss, eval_predictions = self.model.eval(sess, eval_batch)
eval_losses.append(eval_loss)
eval_label_list = list(set(eval_batch["labels"]))
acc, recall, prec, f_beta = get_multi_metrics(pred_y=eval_predictions,
true_y=eval_batch["labels"],
labels=eval_label_list)
eval_accs.append(acc)
eval_recalls.append(recall)
eval_precs.append(prec)
eval_f_betas.append(f_beta)
print("\n")
print("eval: loss: {}, acc: {}, recall: {}, precision: {}, f_beta: {}".format(
mean(eval_losses), mean(eval_accs), mean(eval_recalls),
mean(eval_precs), mean(eval_f_betas)))
print("\n")
if self.config["ckpt_model_path"]:
save_path = os.path.join(os.path.abspath(os.getcwd()),
self.config["ckpt_model_path"])
if not os.path.exists(save_path):
os.makedirs(save_path)
model_save_path = os.path.join(save_path, self.config["model_name"])
self.model.saver.save(sess, model_save_path, global_step=current_step)
# inputs = {"inputs": tf.saved_model.utils.build_tensor_info(self.model.inputs),
# "keep_prob": tf.saved_model.utils.build_tensor_info(self.model.keep_prob)}
#
# outputs = {"predictions": tf.saved_model.utils.build_tensor_info(self.model.predictions)}
#
# prediction_signature = tf.saved_model.signature_def_utils.build_signature_def(inputs=inputs,
# outputs=outputs,
# method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME)
# legacy_init_op = tf.group(tf.tables_initializer(), name="legacy_init_op")
# self.builder.add_meta_graph_and_variables(sess, [tf.saved_model.tag_constants.SERVING],
# signature_def_map={"classifier": prediction_signature},
# legacy_init_op=legacy_init_op)
#
# self.builder.save()
if __name__ == "__main__":
# Read the input information by the user on the command line
parser = argparse.ArgumentParser()
parser.add_argument("--config_path", help="config path of model")
args = parser.parse_args()
trainer = InductionTrainer(args)
trainer.train()
================================================
FILE: prototypical_network/config.json
================================================
{
"model_name": "prototypical",
"epochs": 30,
"checkpoint_every": 500,
"eval_every": 500,
"learning_rate": 1e-3,
"optimization": "adam",
"embedding_size": 300,
"hidden_sizes": [128],
"attention_size": 64,
"num_support": 5,
"num_queries": 5,
"num_classes": 2,
"num_tasks": 1000,
"num_eval_tasks": 500,
"low_freq": 5,
"sequence_length": 100,
"keep_prob": 0.7,
"l2_reg_lambda": 0.0,
"max_grad_norm": 5.0,
"train_data": "../reviews/train",
"eval_data": "../reviews/eval",
"stop_word_path": "../reviews/english",
"output_path": "output/prototypical",
"word_vector_path": "../word_embedded/glove.6B.300d.txt",
"ckpt_model_path": "ckpt_model/prototypical",
"pb_model_path": "pb_model/prototypical"
}
================================================
FILE: prototypical_network/data_helper.py
================================================
"""
data process
"""
import os
import json
import random
import copy
from collections import Counter
from itertools import chain
from typing import Dict, Tuple, Optional, List, Union
import gensim
import numpy as np
class PrototypicalData(object):
def __init__(self, output_path: str, sequence_length: int = 100, num_classes: int = 2, num_support: int = 5,
num_queries: int = 50, num_tasks: int = 1000, num_eval_tasks: int = 100,
stop_word_path: Optional[str] = None,
embedding_size: Optional[int] = None, low_freq: int = 5,
word_vector_path: Optional[str] = None, is_training: bool = True):
"""
init method
:param output_path: path of train/eval data
:param num_classes: number of support class
:param num_support: number of support sample per class
:param num_queries: number of query sample per class
:param num_tasks: number of pre-sampling tasks, this will speeding up train
:param num_eval_tasks: number of pre-sampling tasks in eval stage
:param stop_word_path: path of stop word file
:param embedding_size: embedding size
:param low_freq: frequency of words
:param word_vector_path: path of word vector file(eg. word2vec, glove)
:param is_training: bool
"""
self.__output_path = output_path
if not os.path.exists(self.__output_path):
os.makedirs(self.__output_path)
self.__sequence_length = sequence_length
self.__num_classes = num_classes
self.__num_support = num_support
self.__num_queries = num_queries
self.__num_tasks = num_tasks
self.__num_eval_tasks = num_eval_tasks
self.__stop_word_path = stop_word_path
self.__embedding_size = embedding_size
self.__low_freq = low_freq
self.__word_vector_path = word_vector_path
self.__is_training = is_training
self.vocab_size = None
self.word_vectors = None
self.current_category_index = 0 # record current sample category
print("stop word path: ", self.__stop_word_path)
print("word vector path: ", self.__word_vector_path)
@staticmethod
def load_data(data_path: str) -> Dict[str, Dict[str, List[List[str]]]]:
"""
read train/eval data
:param data_path:
:return: dict. {class_name: {sentiment: [[]], }, ...}
"""
category_files = os.listdir(data_path)
categories_data = {}
for category_file in category_files:
file_path = os.path.join(data_path, category_file)
sentiment_data = {}
with open(file_path, "r", encoding="utf8") as fr:
for line in fr.readlines():
content, label = line.strip().split("\t")
if sentiment_data.get(label, None):
sentiment_data[label].append(content.split(" "))
else:
sentiment_data[label] = [content.split(" ")]
print("task name: ", category_file)
print("pos samples length: ", len(sentiment_data["1"]))
print("neg samples length: ", len(sentiment_data["-1"]))
categories_data[category_file] = sentiment_data
return categories_data
def remove_stop_word(self, data: Dict[str, Dict[str, List[List[str]]]]) -> List[str]:
"""
remove low frequency words and stop words, construct vocab
:param data: {class_name: {sentiment: [[]], }, ...}
:return:
"""
all_words = []
for category, category_data in data.items():
for sentiment, sentiment_data in category_data.items():
all_words.extend(list(chain(*sentiment_data)))
word_count = Counter(all_words) # statistic the frequency of words
sort_word_count = sorted(word_count.items(), key=lambda x: x[1], reverse=True)
# remove low frequency word
words = [item[0] for item in sort_word_count if item[1] > self.__low_freq]
# if stop word file exists, then remove stop words
if self.__stop_word_path:
with open(self.__stop_word_path, "r", encoding="utf8") as fr:
stop_words = [line.strip() for line in fr.readlines()]
words = [word for word in words if word not in stop_words]
return words
def get_word_vectors(self, vocab: List[str]) -> np.ndarray:
"""
load word vector file,
:param vocab: vocab
:return:
"""
pad_vector = np.zeros(self.__embedding_size) # set the "<pad>" vector to 0
word_vectors = (1 / np.sqrt(len(vocab) - 1) * (2 * np.random.rand(len(vocab) - 1, self.__embedding_size) - 1))
word_vectors = np.vstack((pad_vector, word_vectors))
# load glove vectors
glove_vector = {}
with open(self.__word_vector_path, "r", encoding="utf8") as fr:
for line in fr.readlines():
line_list = line.strip().split(" ")
glove_vector[line_list[0]] = line_list[1:]
for i in range(1, len(vocab)):
if glove_vector.get(vocab[i], None):
word_vectors[i, :] = glove_vector[vocab[i]]
else:
print(vocab[i] + "not exist word vector file")
# # load gensim word2vec vectors
# if os.path.splitext(self.__word_vector_path)[-1] == ".bin":
# word_vec = gensim.models.KeyedVectors.load_word2vec_format(self.__word_vector_path, binary=True)
# else:
# word_vec = gensim.models.KeyedVectors.load_word2vec_format(self.__word_vector_path)
#
# for i in range(1, len(vocab)):
# try:
# vector = word_vec.wv[vocab[i]]
# word_vectors[i, :] = vector
# except:
# print(vocab[i] + "not exist word vector file")
return word_vectors
def gen_vocab(self, words: List[str]) -> Dict[str, int]:
"""
generate word_to_index mapping table
:param words:
:return:
"""
if self.__is_training:
vocab = ["<pad>", "<unk>"] + words
self.vocab_size = len(vocab)
if self.__word_vector_path:
word_vectors = self.get_word_vectors(vocab)
self.word_vectors = word_vectors
# save word vector to npy file
np.save(os.path.join(self.__output_path, "word_vectors.npy"), self.word_vectors)
word_to_index = dict(zip(vocab, list(range(len(vocab)))))
# save word_to_index to json file
with open(os.path.join(self.__output_path, "word_to_index.json"), "w") as f:
json.dump(word_to_index, f)
else:
with open(os.path.join(self.__output_path, "word_to_index.json"), "r") as f:
word_to_index = json.load(f)
return word_to_index
@staticmethod
def trans_to_index(data: Dict[str, Dict[str, List[List[str]]]], word_to_index: Dict[str, int]) -> \
Dict[str, Dict[str, List[List[int]]]]:
"""
transformer token to id
:param data:
:param word_to_index:
:return: {class_name: [[], [], ], ..}
"""
data_ids = {category: {sentiment: [[word_to_index.get(token, word_to_index["<unk>"]) for token in line]
for line in sentiment_data]
for sentiment, sentiment_data in category_data.items()}
for category, category_data in data.items()}
return data_ids
def choice_support_query(self, task_data: Dict[str, List[List[int]]])\
-> Tuple[List[List[List[int]]], List[List[int]], List[int]]:
"""
randomly selecting support set, query set form a task.
:param task_data: all data for a task
:return:
"""
label_to_index = {"1": 0, "-1": 1}
if self.__is_training:
with open(os.path.join(self.__output_path, "label_to_index.json"), "w") as f:
json.dump(label_to_index, f)
pos_samples = task_data["1"]
neg_samples = task_data["-1"]
pos_support = random.sample(pos_samples, self.__num_support)
neg_support = random.sample(neg_samples, self.__num_support)
pos_others = copy.copy(pos_samples)
[pos_others.remove(data) for data in pos_support]
neg_others = copy.copy(neg_samples)
[neg_others.remove(data) for data in neg_support]
pos_query = random.sample(pos_others, self.__num_queries)
neg_query = random.sample(neg_others, self.__num_queries)
# padding
pos_support = self.padding(pos_support)
neg_support = self.padding(neg_support)
pos_query = self.padding(pos_query)
neg_query = self.padding(neg_query)
support_set = [pos_support, neg_support] # [num_classes, num_support, sequence_length]
query_set = pos_query + neg_query # [num_classes * num_queries, sequence_length]
labels = [label_to_index["1"]] * len(pos_query) + [label_to_index["-1"]] * len(neg_query)
return support_set, query_set, labels
def samples(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
-> List[Dict[str, Union[List[List[List[int]]], List[List[int]], List[int]]]]:
"""
positive and negative sample from raw data
:param data_ids:
:return:
"""
# product name list
category_list = list(data_ids.keys())
tasks = []
if self.__is_training:
num_tasks = self.__num_tasks
else:
num_tasks = self.__num_eval_tasks
for i in range(num_tasks):
# randomly choice a category to construct train sample
support_category = random.choice(category_list)
support_set, query_set, labels = self.choice_support_query(data_ids[support_category])
tasks.append(dict(support=support_set, queries=query_set, labels=labels))
return tasks
def gen_data(self, file_path: str) -> Dict[str, Dict[str, List[List[int]]]]:
"""
Generate data that is eventually input to the model
:return:
"""
# load data
data = self.load_data(file_path)
# remove stop word
words = self.remove_stop_word(data)
word_to_index = self.gen_vocab(words)
data_ids = self.trans_to_index(data, word_to_index)
return data_ids
def padding(self, sentences: List[List[int]]) -> List[List[int]]:
"""
padding according to the predefined sequence length
:param sentences:
:return:
"""
sentence_pad = [sentence[:self.__sequence_length] if len(sentence) > self.__sequence_length
else sentence + [0] * (self.__sequence_length - len(sentence))
for sentence in sentences]
return sentence_pad
def next_batch(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
-> Dict[str, Union[List[List[List[int]]], List[List[int]], List[int]]]:
"""
train a task at every turn
:param data_ids:
:return:
"""
tasks = self.samples(data_ids)
for task in tasks:
yield task
================================================
FILE: prototypical_network/metrics.py
================================================
"""
performance metrics function
"""
def mean(item: list) -> float:
"""
Calculate the mean of the list
:param item: list object
:return:
"""
res = sum(item) / len(item) if len(item) > 0 else 0
return res
def accuracy(pred_y, true_y):
"""
Calculate accuracy
:param pred_y: predict result
:param true_y: true result
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
corr = 0
for i in range(len(pred_y)):
if pred_y[i] == true_y[i]:
corr += 1
acc = corr / len(pred_y) if len(pred_y) > 0 else 0
return acc
def binary_precision(pred_y, true_y, positive=1):
"""
Calculate the precision of binary classification
:param pred_y: predict result
:param true_y: true result
:param positive: index of positive label
:return:
"""
corr = 0
pred_corr = 0
for i in range(len(pred_y)):
if pred_y[i] == positive:
pred_corr += 1
if pred_y[i] == true_y[i]:
corr += 1
prec = corr / pred_corr if pred_corr > 0 else 0
return prec
def binary_recall(pred_y, true_y, positive=1):
"""
Calculate the recall of binary classification
:param pred_y: predict result
:param true_y: true result
:param positive: index of positive label
:return:
"""
corr = 0
true_corr = 0
for i in range(len(pred_y)):
if true_y[i] == positive:
true_corr += 1
if pred_y[i] == true_y[i]:
corr += 1
rec = corr / true_corr if true_corr > 0 else 0
return rec
def binary_f_beta(pred_y, true_y, beta=1.0, positive=1):
"""
Calculate the f beta of binary classification
:param pred_y: predict result
:param beta: beta parameter
:param true_y: true result
:param positive: index of positive label
:return:
"""
precision = binary_precision(pred_y, true_y, positive)
recall = binary_recall(pred_y, true_y, positive)
try:
f_b = (1 + beta * beta) * precision * recall / (beta * beta * precision + recall)
except:
f_b = 0
return f_b
def get_binary_metrics(pred_y, true_y, f_beta=1.0):
"""
Calculate various performance metrics of binary classification
:param pred_y: predict result
:param true_y: true result
:param f_beta: beta parameter
:return:
"""
acc = accuracy(pred_y, true_y)
recall = binary_recall(pred_y, true_y)
precision = binary_precision(pred_y, true_y)
f_beta = binary_f_beta(pred_y, true_y, f_beta)
return acc, recall, precision, f_beta
def multi_precision(pred_y, true_y, labels):
"""
Calculate the precision of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
precisions = [binary_precision(pred_y, true_y, label) for label in labels]
prec = mean(precisions)
return prec
def multi_recall(pred_y, true_y, labels):
"""
Calculate the recall of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
recalls = [binary_recall(pred_y, true_y, label) for label in labels]
rec = mean(recalls)
return rec
def multi_f_beta(pred_y, true_y, labels, beta=1.0):
"""
Calculate the f value of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:param beta: beta parameter
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
f_betas = [binary_f_beta(pred_y, true_y, beta, label) for label in labels]
f_beta = mean(f_betas)
return f_beta
def get_multi_metrics(pred_y, true_y, labels, f_beta=1.0):
"""
Calculate various performance metrics of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:param beta: beta parameter
:return:
"""
acc = accuracy(pred_y, true_y)
recall = multi_recall(pred_y, true_y, labels)
precision = multi_precision(pred_y, true_y, labels)
f_beta = multi_f_beta(pred_y, true_y, labels, f_beta)
return acc, recall, precision, f_beta
================================================
FILE: prototypical_network/model.py
================================================
"""
prototypical network model for few shot learning
"""
import tensorflow as tf
class PrototypicalModel(object):
def __init__(self, config, vocab_size, word_vectors):
self.config = config
self.vocab_size = vocab_size
self.word_vectors = word_vectors
# [num_classes, num_support, sequence_length]
self.support = tf.placeholder(tf.int32, [None, None, None], name="support")
# [num_classes * num_queries, sequence_length]
self.queries = tf.placeholder(tf.int32, [None, None], name="queries")
# [num_classes * num_queries]
self.labels = tf.placeholder(tf.int32, [None], name="labels")
self.keep_prob = tf.placeholder(tf.float32, name="keep_prob") # dropout
self.l2_loss = tf.constant(0.0) # l2 regulation
# construct graph
self.model_structure()
# Initialize the object that saves the model
self.init_saver()
def model_structure(self):
# embedding layer
with tf.name_scope("embedding"):
# Initialization of Word Embedding Matrix Using Pre-trained Word Vectors
if self.word_vectors is not None:
embedding_w = tf.Variable(tf.cast(self.word_vectors, dtype=tf.float32, name="word2vec"),
name="embedding_w")
else:
embedding_w = tf.get_variable("embedding_w", shape=[self.vocab_size, self.config["embedding_size"]],
initializer=tf.random_normal_initializer())
# support embedding. dimension: [num_classes, num_support, sequence_length, embedding_size]
support_embedded = tf.nn.embedding_lookup(embedding_w, self.support, name="support_embedded")
# query embedding. dimension: [num_classes * num_queries, sequence_length, embedding_size]
queries_embedded = tf.nn.embedding_lookup(embedding_w, self.queries, name="queries_embedded")
# reshape support set to 3 dimensions
support_embedded_reshape = tf.reshape(support_embedded,
[-1, self.config["sequence_length"], self.config["embedding_size"]])
with tf.name_scope("Bi-LSTM"):
for idx, hidden_size in enumerate(self.config["hidden_sizes"]):
with tf.name_scope("Bi-LSTM" + str(idx)):
# frontward lstm cell
lstm_fw_cell = tf.nn.rnn_cell.DropoutWrapper(
tf.nn.rnn_cell.LSTMCell(num_units=hidden_size, initializer=tf.orthogonal_initializer(),
state_is_tuple=True),
output_keep_prob=self.keep_prob)
# backward lstm cell
lstm_bw_cell = tf.nn.rnn_cell.DropoutWrapper(
tf.nn.rnn_cell.LSTMCell(num_units=hidden_size, initializer=tf.orthogonal_initializer(),
state_is_tuple=True),
output_keep_prob=self.keep_prob)
# bi-lstm dynamic decode
support_output, _ = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell, lstm_bw_cell,
support_embedded_reshape,
dtype=tf.float32,
scope="bi-lstm_1" + str(idx))
queries_output, _ = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell, lstm_bw_cell,
queries_embedded,
dtype=tf.float32,
scope="bi-lstm_2" + str(idx))
# concat frontward and backward output of lstm
support_embedded_reshape = tf.concat(support_output, -1)
queries_embedded = tf.concat(queries_output, -1)
with tf.name_scope("final_step_output"):
# # [num_classes * num_support, hidden_size * 2]
# support_final_output = self._attention(support_embedded_reshape, scope_name="support")
# # [num_classes * num_queries, hidden_size * 2]
# queries_final_output = self._attention(queries_embedded, scope_name="queries")
# [num_classes * num_support, hidden_size * 2]
support_final_output = support_embedded_reshape[:, -1, :]
# [num_classes * num_queries, hidden_size * 2]
queries_final_output = queries_embedded[:, -1, :]
# [num_classes, num_support, embedding_size]
support_final_output = tf.reshape(support_final_output,
[self.config["num_classes"],
self.config["num_support"],
-1])
# computing class vector means. dimension: [num_classes, embedding_size]
support_class_output = tf.reduce_mean(support_final_output, axis=1)
# ---------------------------------------------------------------------------------------
# squared Euclidean distance + cross entropy loss function
# ---------------------------------------------------------------------------------------
with tf.name_scope("euclidean_distance"):
# expand dimension. [nun_classes * num_queries, num_classes, embedding_size]
support_class_output_expand = tf.tile(tf.expand_dims(support_class_output, axis=0),
(self.config["num_classes"] * self.config["num_queries"], 1, 1))
# expand dimension. dimension same as above
queries_output_expand = tf.tile(tf.expand_dims(queries_final_output, axis=1),
(1, self.config["num_classes"], 1))
# distance between queries set and class in support set. [num_classes * num_queries, num_classes]
distance = -tf.reduce_mean(tf.square(support_class_output_expand - queries_output_expand),
axis=2, name="distance")
self.predictions = tf.argmax(distance, axis=-1, name="predictions")
with tf.name_scope("loss"):
losses = tf.nn.sparse_softmax_cross_entropy_with_logits(logits=distance, labels=self.labels)
self.loss = tf.reduce_mean(losses, name="loss")
with tf.name_scope("train_op"):
# define optimizer
optimizer = self.get_optimizer()
trainable_params = tf.trainable_variables()
gradients = tf.gradients(self.loss, trainable_params)
# gradient clip
clip_gradients, _ = tf.clip_by_global_norm(gradients, self.config["max_grad_norm"])
self.train_op = optimizer.apply_gradients(zip(clip_gradients, trainable_params))
def _attention(self, H, scope_name):
"""
attention for the final output of Lstm
:param H: [batch_size, sequence_length, hidden_size * 2]
"""
with tf.variable_scope(scope_name):
hidden_size = self.config["hidden_sizes"][-1] * 2
attention_size = self.config["attention_size"]
w_1 = tf.get_variable("w_1", shape=[hidden_size, attention_size],
initializer=tf.glorot_normal_initializer)
w_2 = tf.Variable(tf.random_normal([attention_size], stddev=0.1))
# Nonlinear conversion for LSTM output, [batch_size * sequence_length, attention_size]
M = tf.tanh(tf.matmul(tf.reshape(H, [-1, hidden_size]), w_1))
# calculate weights, [batch_size, sequence_length]
weights = tf.reshape(tf.matmul(M, tf.reshape(w_2, [-1, 1])),
[-1, self.config["sequence_length"]])
# softmax normalization, [batch_size, sequence_length]
alpha = tf.nn.softmax(weights, axis=-1)
# calculate weighted sum
# r = tf.matmul(tf.transpose(H, [0, 2, 1]), tf.reshape(alpha, [-1, self.config["sequence_length"], 1]))
# print(r)
output = tf.reduce_sum(H * tf.reshape(alpha, [-1, self.config["sequence_length"], 1]), axis=1)
return output
def get_optimizer(self):
"""
define optimizer
:return:
"""
optimizer = None
if self.config["optimization"] == "adam":
optimizer = tf.train.AdamOptimizer(self.config["learning_rate"])
if self.config["optimization"] == "rmsprop":
optimizer = tf.train.RMSPropOptimizer(self.config["learning_rate"])
if self.config["optimization"] == "sgd":
optimizer = tf.train.GradientDescentOptimizer(self.config["learning_rate"])
return optimizer
def init_saver(self):
"""
init model saver object
:return:
"""
self.saver = tf.train.Saver(tf.global_variables())
def train(self, sess, batch, dropout_prob):
"""
train model method
:param sess: session object of tensorflow
:param batch: train batch data
:param dropout_prob: dropout keep prob
:return: loss, predict result
"""
feed_dict = {self.support: batch["support"],
self.queries: batch["queries"],
self.labels: batch["labels"],
self.keep_prob: dropout_prob}
_, loss, predictions = sess.run([self.train_op, self.loss, self.predictions],
feed_dict=feed_dict)
return loss, predictions
def eval(self, sess, batch):
"""
evaluate model method
:param sess: session object of tensorflow
:param batch: eval batch data
:return: loss, predict result
"""
feed_dict = {self.support: batch["support"],
self.queries: batch["queries"],
self.labels: batch["labels"],
self.keep_prob: 1.0}
loss, predictions = sess.run([self.loss, self.predictions], feed_dict=feed_dict)
return loss, predictions
def infer(self, sess, batch):
"""
infer model method
:param sess:
:param batch:
:return: predict result
"""
feed_dict = {self.support: batch["support"],
self.queries: batch["queries"],
self.keep_prob: 1.0}
predict = sess.run(self.predictions, feed_dict=feed_dict)
return predict
================================================
FILE: prototypical_network/trainer.py
================================================
import json
import os
import argparse
import tensorflow as tf
from data_helper import PrototypicalData
from model import PrototypicalModel
from metrics import get_multi_metrics, mean
class PrototypicalTrainer(object):
def __init__(self, args):
self.args = args
with open(args.config_path, "r") as fr:
self.config = json.load(fr)
# self.builder = tf.saved_model.builder.SavedModelBuilder("../pb_model/weibo/bilstm/savedModel")
# load date set
self.train_data_obj = self.load_data()
self.eval_data_obj = self.load_data(is_training=False)
self.train_tasks = self.train_data_obj.gen_data(self.config["train_data"])
self.eval_tasks = self.eval_data_obj.gen_data(self.config["eval_data"])
print("vocab size: ", self.train_data_obj.vocab_size)
self.model = self.create_model()
def load_data(self, is_training=True):
"""
init data object
:return:
"""
data_obj = PrototypicalData(output_path=self.config["output_path"],
sequence_length=self.config["sequence_length"],
num_classes=self.config["num_classes"],
num_support=self.config["num_support"],
num_queries=self.config["num_queries"],
num_tasks=self.config["num_tasks"],
num_eval_tasks=self.config["num_eval_tasks"],
embedding_size=self.config["embedding_size"],
stop_word_path=self.config["stop_word_path"],
word_vector_path=self.config["word_vector_path"],
is_training=is_training)
return data_obj
def create_model(self):
"""
init model object
:return:
"""
model = PrototypicalModel(config=self.config, vocab_size=self.train_data_obj.vocab_size,
word_vectors=self.train_data_obj.word_vectors)
return model
def train(self):
"""
train model
:return:
"""
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.5, allow_growth=True)
sess_config = tf.ConfigProto(log_device_placement=False, allow_soft_placement=True, gpu_options=gpu_options)
with tf.Session(config=sess_config) as sess:
# init all variable in graph
sess.run(tf.global_variables_initializer())
current_step = 0
for epoch in range(self.config["epochs"]):
print("----- Epoch {}/{} -----".format(epoch + 1, self.config["epochs"]))
for batch in self.train_data_obj.next_batch(self.train_tasks):
loss, predictions = self.model.train(sess, batch, self.config["keep_prob"])
label_list = list(set(batch["labels"]))
acc, recall, prec, f_beta = get_multi_metrics(pred_y=predictions, true_y=batch["labels"],
labels=label_list)
print("train: step: {}, loss: {}, acc: {}, recall: {}, precision: {}, f_beta: {}".format(
current_step, loss, acc, recall, prec, f_beta))
current_step += 1
if current_step % self.config["checkpoint_every"] == 0:
eval_losses = []
eval_accs = []
eval_recalls = []
eval_precs = []
eval_f_betas = []
for eval_batch in self.train_data_obj.next_batch(self.eval_tasks):
eval_loss, eval_predictions = self.model.eval(sess, eval_batch)
eval_losses.append(eval_loss)
eval_label_list = list(set(eval_batch["labels"]))
acc, recall, prec, f_beta = get_multi_metrics(pred_y=eval_predictions,
true_y=eval_batch["labels"],
labels=eval_label_list)
eval_accs.append(acc)
eval_recalls.append(recall)
eval_precs.append(prec)
eval_f_betas.append(f_beta)
print("\n")
print("eval: loss: {}, acc: {}, recall: {}, precision: {}, f_beta: {}".format(
mean(eval_losses), mean(eval_accs), mean(eval_recalls),
mean(eval_precs), mean(eval_f_betas)))
print("\n")
if self.config["ckpt_model_path"]:
save_path = os.path.join(os.path.abspath(os.getcwd()),
self.config["ckpt_model_path"])
if not os.path.exists(save_path):
os.makedirs(save_path)
model_save_path = os.path.join(save_path, self.config["model_name"])
self.model.saver.save(sess, model_save_path, global_step=current_step)
# inputs = {"inputs": tf.saved_model.utils.build_tensor_info(self.model.inputs),
# "keep_prob": tf.saved_model.utils.build_tensor_info(self.model.keep_prob)}
#
# outputs = {"predictions": tf.saved_model.utils.build_tensor_info(self.model.predictions)}
#
# prediction_signature = tf.saved_model.signature_def_utils.build_signature_def(inputs=inputs,
# outputs=outputs,
# method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME)
# legacy_init_op = tf.group(tf.tables_initializer(), name="legacy_init_op")
# self.builder.add_meta_graph_and_variables(sess, [tf.saved_model.tag_constants.SERVING],
# signature_def_map={"classifier": prediction_signature},
# legacy_init_op=legacy_init_op)
#
# self.builder.save()
if __name__ == "__main__":
# Read the input information by the user on the command line
parser = argparse.ArgumentParser()
parser.add_argument("--config_path", help="config path of model")
args = parser.parse_args()
trainer = PrototypicalTrainer(args)
trainer.train()
================================================
FILE: relation_network/config.json
================================================
{
"model_name": "relation",
"epochs": 30,
"checkpoint_every": 500,
"eval_every": 500,
"learning_rate": 1e-3,
"optimization": "adam",
"embedding_size": 300,
"hidden_sizes": [64],
"layer_size": 100,
"attention_size": 64,
"num_support": 5,
"num_queries": 5,
"num_classes": 2,
"num_tasks": 1000,
"num_eval_tasks": 100,
"low_freq": 5,
"sequence_length": 100,
"keep_prob": 0.5,
"l2_reg_lambda": 0.0,
"max_grad_norm": 5.0,
"train_data": "../reviews/train",
"eval_data": "../reviews/eval",
"stop_word_path": "../reviews/english",
"output_path": "output/relation",
"word_vector_path": "../word_embedded/glove.6B.300d.txt",
"ckpt_model_path": "ckpt_model/relation",
"pb_model_path": "pb_model/relation"
}
================================================
FILE: relation_network/data_helper.py
================================================
"""
data process
"""
import os
import json
import random
import copy
from collections import Counter
from itertools import chain
from typing import Dict, Tuple, Optional, List, Union
import gensim
import numpy as np
class RelationData(object):
def __init__(self, output_path: str, sequence_length: int = 100, num_classes: int = 2, num_support: int = 5,
num_queries: int = 50, num_tasks: int = 1000, num_eval_tasks: int = 100,
stop_word_path: Optional[str] = None,
embedding_size: Optional[int] = None, low_freq: int = 5,
word_vector_path: Optional[str] = None, is_training: bool = True):
"""
init method
:param output_path: path of train/eval data
:param num_classes: number of support class
:param num_support: number of support sample per class
:param num_queries: number of query sample per class
:param num_tasks: number of pre-sampling tasks, this will speeding up train
:param num_eval_tasks: number of pre-sampling tasks in eval stage
:param stop_word_path: path of stop word file
:param embedding_size: embedding size
:param low_freq: frequency of words
:param word_vector_path: path of word vector file(eg. word2vec, glove)
:param is_training: bool
"""
self.__output_path = output_path
if not os.path.exists(self.__output_path):
os.makedirs(self.__output_path)
self.__sequence_length = sequence_length
self.__num_classes = num_classes
self.__num_support = num_support
self.__num_queries = num_queries
self.__num_tasks = num_tasks
self.__num_eval_tasks = num_eval_tasks
self.__stop_word_path = stop_word_path
self.__embedding_size = embedding_size
self.__low_freq = low_freq
self.__word_vector_path = word_vector_path
self.__is_training = is_training
self.vocab_size = None
self.word_vectors = None
self.current_category_index = 0 # record current sample category
print("stop word path: ", self.__stop_word_path)
print("word vector path: ", self.__word_vector_path)
@staticmethod
def load_data(data_path: str) -> Dict[str, Dict[str, List[List[str]]]]:
"""
read train/eval data
:param data_path:
:return: dict. {class_name: {sentiment: [[]], }, ...}
"""
category_files = os.listdir(data_path)
categories_data = {}
for category_file in category_files:
file_path = os.path.join(data_path, category_file)
sentiment_data = {}
with open(file_path, "r", encoding="utf8") as fr:
for line in fr.readlines():
content, label = line.strip().split("\t")
if sentiment_data.get(label, None):
sentiment_data[label].append(content.split(" "))
else:
sentiment_data[label] = [content.split(" ")]
print("task name: ", category_file)
print("pos samples length: ", len(sentiment_data["1"]))
print("neg samples length: ", len(sentiment_data["-1"]))
categories_data[category_file] = sentiment_data
return categories_data
def remove_stop_word(self, data: Dict[str, Dict[str, List[List[str]]]]) -> List[str]:
"""
remove low frequency words and stop words, construct vocab
:param data: {class_name: {sentiment: [[]], }, ...}
:return:
"""
all_words = []
for category, category_data in data.items():
for sentiment, sentiment_data in category_data.items():
all_words.extend(list(chain(*sentiment_data)))
word_count = Counter(all_words) # statistic the frequency of words
sort_word_count = sorted(word_count.items(), key=lambda x: x[1], reverse=True)
# remove low frequency word
words = [item[0] for item in sort_word_count if item[1] > self.__low_freq]
# if stop word file exists, then remove stop words
if self.__stop_word_path:
with open(self.__stop_word_path, "r", encoding="utf8") as fr:
stop_words = [line.strip() for line in fr.readlines()]
words = [word for word in words if word not in stop_words]
return words
def get_word_vectors(self, vocab: List[str]) -> np.ndarray:
"""
load word vector file,
:param vocab: vocab
:return:
"""
pad_vector = np.zeros(self.__embedding_size) # set the "<pad>" vector to 0
word_vectors = (1 / np.sqrt(len(vocab) - 1) * (2 * np.random.rand(len(vocab) - 1, self.__embedding_size) - 1))
word_vectors = np.vstack((pad_vector, word_vectors))
# load glove vectors
glove_vector = {}
with open(self.__word_vector_path, "r", encoding="utf8") as fr:
for line in fr.readlines():
line_list = line.strip().split(" ")
glove_vector[line_list[0]] = line_list[1:]
for i in range(1, len(vocab)):
if glove_vector.get(vocab[i], None):
word_vectors[i, :] = glove_vector[vocab[i]]
else:
print(vocab[i] + "not exist word vector file")
# # load gensim word2vec vectors
# if os.path.splitext(self.__word_vector_path)[-1] == ".bin":
# word_vec = gensim.models.KeyedVectors.load_word2vec_format(self.__word_vector_path, binary=True)
# else:
# word_vec = gensim.models.KeyedVectors.load_word2vec_format(self.__word_vector_path)
#
# for i in range(1, len(vocab)):
# try:
# vector = word_vec.wv[vocab[i]]
# word_vectors[i, :] = vector
# except:
# print(vocab[i] + "not exist word vector file")
return word_vectors
def gen_vocab(self, words: List[str]) -> Dict[str, int]:
"""
generate word_to_index mapping table
:param words:
:return:
"""
if self.__is_training:
vocab = ["<pad>", "<unk>"] + words
self.vocab_size = len(vocab)
if self.__word_vector_path:
word_vectors = self.get_word_vectors(vocab)
self.word_vectors = word_vectors
# save word vector to npy file
np.save(os.path.join(self.__output_path, "word_vectors.npy"), self.word_vectors)
word_to_index = dict(zip(vocab, list(range(len(vocab)))))
# save word_to_index to json file
with open(os.path.join(self.__output_path, "word_to_index.json"), "w") as f:
json.dump(word_to_index, f)
else:
with open(os.path.join(self.__output_path, "word_to_index.json"), "r") as f:
word_to_index = json.load(f)
return word_to_index
@staticmethod
def trans_to_index(data: Dict[str, Dict[str, List[List[str]]]], word_to_index: Dict[str, int]) -> \
Dict[str, Dict[str, List[List[int]]]]:
"""
transformer token to id
:param data:
:param word_to_index:
:return: {class_name: [[], [], ], ..}
"""
data_ids = {category: {sentiment: [[word_to_index.get(token, word_to_index["<unk>"]) for token in line]
for line in sentiment_data]
for sentiment, sentiment_data in category_data.items()}
for category, category_data in data.items()}
return data_ids
def choice_support_query(self, task_data: Dict[str, List[List[int]]])\
-> Tuple[List[List[List[int]]], List[List[int]], List[int]]:
"""
randomly selecting support set, query set form a task.
:param task_data: all data for a task
:return:
"""
label_to_index = {"1": 0, "-1": 1}
if self.__is_training:
with open(os.path.join(self.__output_path, "label_to_index.json"), "w") as f:
json.dump(label_to_index, f)
pos_samples = task_data["1"]
neg_samples = task_data["-1"]
pos_support = random.sample(pos_samples, self.__num_support)
neg_support = random.sample(neg_samples, self.__num_support)
pos_others = copy.copy(pos_samples)
[pos_others.remove(data) for data in pos_support]
neg_others = copy.copy(neg_samples)
[neg_others.remove(data) for data in neg_support]
pos_query = random.sample(pos_others, self.__num_queries)
neg_query = random.sample(neg_others, self.__num_queries)
# padding
pos_support = self.padding(pos_support)
neg_support = self.padding(neg_support)
pos_query = self.padding(pos_query)
neg_query = self.padding(neg_query)
support_set = [pos_support, neg_support] # [num_classes, num_support, sequence_length]
query_set = pos_query + neg_query # [num_classes * num_queries, sequence_length]
labels = [label_to_index["1"]] * len(pos_query) + [label_to_index["-1"]] * len(neg_query)
return support_set, query_set, labels
def samples(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
-> List[Dict[str, Union[List[List[List[int]]], List[List[int]], List[int]]]]:
"""
positive and negative sample from raw data
:param data_ids:
:return:
"""
# product name list
category_list = list(data_ids.keys())
tasks = []
if self.__is_training:
num_tasks = self.__num_tasks
else:
num_tasks = self.__num_eval_tasks
for i in range(num_tasks):
# randomly choice a category to construct train sample
support_category = random.choice(category_list)
support_set, query_set, labels = self.choice_support_query(data_ids[support_category])
tasks.append(dict(support=support_set, queries=query_set, labels=labels))
return tasks
def gen_data(self, file_path: str) -> Dict[str, Dict[str, List[List[int]]]]:
"""
Generate data that is eventually input to the model
:return:
"""
# load data
data = self.load_data(file_path)
# remove stop word
words = self.remove_stop_word(data)
word_to_index = self.gen_vocab(words)
data_ids = self.trans_to_index(data, word_to_index)
return data_ids
def padding(self, sentences: List[List[int]]) -> List[List[int]]:
"""
padding according to the predefined sequence length
:param sentences:
:return:
"""
sentence_pad = [sentence[:self.__sequence_length] if len(sentence) > self.__sequence_length
else sentence + [0] * (self.__sequence_length - len(sentence))
for sentence in sentences]
return sentence_pad
def next_batch(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
-> Dict[str, Union[List[List[List[int]]], List[List[int]], List[int]]]:
"""
train a task at every turn
:param data_ids:
:return:
"""
tasks = self.samples(data_ids)
for task in tasks:
yield task
================================================
FILE: relation_network/metrics.py
================================================
"""
performance metrics function
"""
def mean(item: list) -> float:
"""
Calculate the mean of the list
:param item: list object
:return:
"""
res = sum(item) / len(item) if len(item) > 0 else 0
return res
def accuracy(pred_y, true_y):
"""
Calculate accuracy
:param pred_y: predict result
:param true_y: true result
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
corr = 0
for i in range(len(pred_y)):
if pred_y[i] == true_y[i]:
corr += 1
acc = corr / len(pred_y) if len(pred_y) > 0 else 0
return acc
def binary_precision(pred_y, true_y, positive=1):
"""
Calculate the precision of binary classification
:param pred_y: predict result
:param true_y: true result
:param positive: index of positive label
:return:
"""
corr = 0
pred_corr = 0
for i in range(len(pred_y)):
if pred_y[i] == positive:
pred_corr += 1
if pred_y[i] == true_y[i]:
corr += 1
prec = corr / pred_corr if pred_corr > 0 else 0
return prec
def binary_recall(pred_y, true_y, positive=1):
"""
Calculate the recall of binary classification
:param pred_y: predict result
:param true_y: true result
:param positive: index of positive label
:return:
"""
corr = 0
true_corr = 0
for i in range(len(pred_y)):
if true_y[i] == positive:
true_corr += 1
if pred_y[i] == true_y[i]:
corr += 1
rec = corr / true_corr if true_corr > 0 else 0
return rec
def binary_f_beta(pred_y, true_y, beta=1.0, positive=1):
"""
Calculate the f beta of binary classification
:param pred_y: predict result
:param beta: beta parameter
:param true_y: true result
:param positive: index of positive label
:return:
"""
precision = binary_precision(pred_y, true_y, positive)
recall = binary_recall(pred_y, true_y, positive)
try:
f_b = (1 + beta * beta) * precision * recall / (beta * beta * precision + recall)
except:
f_b = 0
return f_b
def get_binary_metrics(pred_y, true_y, f_beta=1.0):
"""
Calculate various performance metrics of binary classification
:param pred_y: predict result
:param true_y: true result
:param f_beta: beta parameter
:return:
"""
acc = accuracy(pred_y, true_y)
recall = binary_recall(pred_y, true_y)
precision = binary_precision(pred_y, true_y)
f_beta = binary_f_beta(pred_y, true_y, f_beta)
return acc, recall, precision, f_beta
def multi_precision(pred_y, true_y, labels):
"""
Calculate the precision of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
precisions = [binary_precision(pred_y, true_y, label) for label in labels]
prec = mean(precisions)
return prec
def multi_recall(pred_y, true_y, labels):
"""
Calculate the recall of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
recalls = [binary_recall(pred_y, true_y, label) for label in labels]
rec = mean(recalls)
return rec
def multi_f_beta(pred_y, true_y, labels, beta=1.0):
"""
Calculate the f value of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:param beta: beta parameter
:return:
"""
if isinstance(pred_y[0], list):
pred_y = [item[0] for item in pred_y]
f_betas = [binary_f_beta(pred_y, true_y, beta, label) for label in labels]
f_beta = mean(f_betas)
return f_beta
def get_multi_metrics(pred_y, true_y, labels, f_beta=1.0):
"""
Calculate various performance metrics of multi classification
:param pred_y: predict result
:param true_y: true result
:param labels: label list
:param beta: beta parameter
:return:
"""
acc = accuracy(pred_y, true_y)
recall = multi_recall(pred_y, true_y, labels)
precision = multi_precision(pred_y, true_y, labels)
f_beta = multi_f_beta(pred_y, true_y, labels, f_beta)
return acc, recall, precision, f_beta
================================================
FILE: relation_network/model.py
================================================
"""
prototypical network model for few shot learning
"""
import tensorflow as tf
class RelationModel(object):
def __init__(self, config, vocab_size, word_vectors):
self.config = config
self.vocab_size = vocab_size
self.word_vectors = word_vectors
# [num_classes, num_support, sequence_length]
self.support = tf.placeholder(tf.int32, [None, None, None], name="support")
# [num_classes * num_queries, sequence_length]
self.queries = tf.placeholder(tf.int32, [None, None], name="queries")
# [num_classes * num_queries]
self.labels = tf.placeholder(tf.int32, [None], name="labels")
self.keep_prob = tf.placeholder(tf.float32, name="keep_prob") # dropout
self.l2_loss = tf.constant(0.0) # l2 regulation
# construct graph
self.model_structure()
# Initialize the object that saves the model
self.init_saver()
def model_structure(self):
# embedding layer
with tf.name_scope("embedding"):
# Initialization of Word Embedding Matrix Using Pre-trained Word Vectors
if self.word_vectors is not None:
embedding_w = tf.Variable(tf.cast(self.word_vectors, dtype=tf.float32, name="word2vec"),
name="embedding_w")
else:
embedding_w = tf.get_variable("embedding_w", shape=[self.vocab_size, self.config["embedding_size"]],
initializer=tf.random_normal_initializer())
# support embedding. dimension: [num_classes, num_support, sequence_length, embedding_size]
support_embedded = tf.nn.embedding_lookup(embedding_w, self.support, name="support_embedded")
# query embedding. dimension: [num_classes * num_queries, sequence_length, embedding_size]
queries_embedded = tf.nn.embedding_lookup(embedding_w, self.queries, name="queries_embedded")
# reshape support set to 3 dimensions
support_embedded_reshape = tf.reshape(support_embedded,
[-1, self.config["sequence_length"], self.config["embedding_size"]])
with tf.name_scope("Bi-LSTM"):
for idx, hidden_size in enumerate(self.config["hidden_sizes"]):
with tf.name_scope("Bi-LSTM" + str(idx)):
# frontward lstm cell
lstm_fw_cell = tf.nn.rnn_cell.DropoutWrapper(
tf.nn.rnn_cell.LSTMCell(num_units=hidden_size, initializer=tf.orthogonal_initializer(),
state_is_tuple=True),
output_keep_prob=self.keep_prob)
# backward lstm cell
lstm_bw_cell = tf.nn.rnn_cell.DropoutWrapper(
tf.nn.rnn_cell.LSTMCell(num_units=hidden_size, initializer=tf.orthogonal_initializer(),
state_is_tuple=True),
output_keep_prob=self.keep_prob)
# bi-lstm dynamic decode
support_output, _ = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell, lstm_bw_cell,
support_embedded_reshape,
dtype=tf.float32,
scope="bi-lstm_1" + str(idx))
queries_output, _ = tf.nn.bidirectional_dynamic_rnn(lstm_fw_cell, lstm_bw_cell,
queries_embedded,
dtype=tf.float32,
scope="bi-lstm_2" + str(idx))
# concat frontward and backward output of lstm
support_embedded_reshape = tf.concat(support_output, -1)
queries_embedded = tf.concat(queries_output, -1)
with tf.name_scope("concat_support_query"):
# [num_classes * num_support, hidden_size * 2]
support_final_output = self._attention(support_embedded_reshape, scope_name="support")
# [num_classes * num_queries, hidden_size * 2]
queries_final_output = self._attention(queries_embedded, scope_name="queries")
# [num_classes, num_support, hidden_size * 2]
support_final_output = tf.reshape(support_final_output,
[self.config["num_classes"],
self.config["num_support"],
self.config["hidden_sizes"][-1] * 2])
# computing class vector means. dimension: [num_classes, hidden_size * 2]
support_class_final_output = tf.reduce_mean(support_final_output, axis=1)
# define relation module
with tf.name_scope("relation_layer"):
scores = self.neural_tensor_layer(support_class_final_output, queries_final_output)
self.predictions = tf.argmax(scores, axis=-1, name="predictions")
with tf.name_scope("loss"):
labels_one_hot = tf.one_hot(self.labels, self.config["num_classes"], dtype=tf.float32)
self.loss = tf.losses.mean_squared_error(labels=labels_one_hot, predictions=scores)
with tf.name_scope("train_op"):
# define optimizer
optimizer = self.get_optimizer()
trainable_params = tf.trainable_variables()
gradients = tf.gradients(self.loss, trainable_params)
# gradient clip
clip_gradients, _ = tf.clip_by_global_norm(gradients, self.config["max_grad_norm"])
self.train_op = optimizer.apply_gradients(zip(clip_gradients, trainable_params))
def neural_tensor_layer(self, class_vector, query_encoder):
"""
calculate relation scores
:param class_vector: class vectors
:param query_encoder: query set encoding matrix. [num_classes * num_queries, encode_size]
:return:
"""
num_classes = self.config["num_classes"]
encode_size = self.config["hidden_sizes"][-1] * 2
layer_size = self.config["layer_size"]
M = tf.get_variable("M", [encode_size, encode_size, layer_size], dtype=tf.float32,
initializer=tf.truncated_normal_initializer(stddev=(2 / encode_size) ** 0.5))
# 该层可以理解为从不同的视角去计算类向量和query向量的分数
# [[class1, class2, ..], [class1, class2, ..], ... layer_size]
all_mid = []
for i in range(layer_size):
# [num_classes, num_classes * num_queries]
slice_mid = tf.matmul(tf.matmul(class_vector, M[:, :, i]), query_encoder, transpose_b=True)
all_mid.append(tf.split(slice_mid, [1] * num_classes, axis=0))
# [[1, 2, .. layer_size], ... class_n], 将同一个类经tensor layer计算出来的分数放在一起
all_mid = [[mid[j] for mid in all_mid] for j in range(len(all_mid[0]))]
# [layer_size, num_classes * num_queries]
all_mid_concat = [tf.concat(mid, axis=0) for mid in all_mid]
# [num_classes * num_queries, layer_size]
all_mid_transpose = [tf.nn.relu(tf.transpose(mid)) for mid in all_mid_concat]
relation_w = tf.get_variable("relation_w", [layer_size, 1], dtype=tf.float32,
initializer=tf.glorot_normal_initializer())
relation_b = tf.get_variable("relation_b", [1], dtype=tf.float32,
initializer=tf.glorot_normal_initializer())
scores = []
for mid in all_mid_transpose:
score = tf.nn.sigmoid(tf.matmul(mid, relation_w) + relation_b)
scores.append(score)
# [num_classes * num_queries, num_classes]
scores = tf.concat(scores, axis=-1)
return scores
def _attention(self, H, scope_name):
"""
attention for the final output of Lstm
:param H: [batch_size, sequence_length, hidden_size * 2]
"""
with tf.variable_scope(scope_name):
hidden_size = self.config["hidden_sizes"][-1] * 2
attention_size = self.config["attention_size"]
w_1 = tf.get_variable("w_1", shape=[hidden_size, attention_size],
initializer=tf.glorot_normal_initializer)
w_2 = tf.Variable(tf.random_normal([attention_size], stddev=0.1))
# Nonlinear conversion for LSTM output, [batch_size * sequence_length, attention_size]
M = tf.tanh(tf.matmul(tf.reshape(H, [-1, hidden_size]), w_1))
# calculate weights, [batch_size, sequence_length]
weights = tf.reshape(tf.matmul(M, tf.reshape(w_2, [-1, 1])),
[-1, self.config["sequence_length"]])
# softmax normalization, [batch_size, sequence_length]
alpha = tf.nn.softmax(weights, axis=-1)
# calculate weighted sum
# r = tf.matmul(tf.transpose(H, [0, 2, 1]), tf.reshape(alpha, [-1, self.config["sequence_length"], 1]))
# print(r)
output = tf.reduce_sum(H * tf.reshape(alpha, [-1, self.config["sequence_length"], 1]), axis=1)
return output
def get_optimizer(self):
"""
define optimizer
:return:
"""
optimizer = None
if self.config["optimization"] == "adam":
optimizer = tf.train.AdamOptimizer(self.config["learning_rate"])
if self.config["optimization"] == "rmsprop":
optimizer = tf.train.RMSPropOptimizer(self.config["learning_rate"])
if self.config["optimization"] == "sgd":
optimizer = tf.train.GradientDescentOptimizer(self.config["learning_rate"])
return optimizer
def init_saver(self):
"""
init model saver object
:return:
"""
self.saver = tf.train.Saver(tf.global_variables())
def train(self, sess, batch, dropout_prob):
"""
train model method
:param sess: session object of tensorflow
:param batch: train batch data
:param dropout_prob: dropout keep prob
:return: loss, predict result
"""
feed_dict = {self.support: batch["support"],
self.queries: batch["queries"],
self.labels: batch["labels"],
self.keep_prob: dropout_prob}
# 训练模型
_, loss, predictions = sess.run([self.train_op, self.loss, self.predictions],
feed_dict=feed_dict)
return loss, predictions
def eval(self, sess, batch):
"""
evaluate model method
:param sess: session object of tensorflow
:param batch: eval batch data
:return: loss, predict result
"""
feed_dict = {self.support: batch["support"],
self.queries: batch["queries"],
self.labels: batch["labels"],
self.keep_prob: 1.0}
loss, predictions = sess.run([self.loss, self.predictions], feed_dict=feed_dict)
return loss, predictions
def infer(self, sess, batch):
"""
infer model method
:param sess:
:param batch:
:return: predict result
"""
feed_dict = {self.support: batch["support"],
self.queries: batch["queries"],
self.keep_prob: 1.0}
predict = sess.run(self.predictions, feed_dict=feed_dict)
return predict
================================================
FILE: relation_network/trainer.py
================================================
import json
import os
import argparse
import tensorflow as tf
from data_helper import RelationData
from model import RelationModel
from metrics import get_multi_metrics, mean
class RelationTrainer(object):
def __init__(self, args):
self.args = args
with open(args.config_path, "r") as fr:
self.config = json.load(fr)
# self.builder = tf.saved_model.builder.SavedModelBuilder("../pb_model/weibo/bilstm/savedModel")
# load date set
self.train_data_obj = self.load_data()
self.eval_data_obj = self.load_data(is_training=False)
self.train_tasks = self.train_data_obj.gen_data(self.config["train_data"])
self.eval_tasks = self.eval_data_obj.gen_data(self.config["eval_data"])
print("number of train tasks: ", len(self.train_tasks))
self.model = self.create_model()
def load_data(self, is_training=True):
"""
init data object
:return:
"""
data_obj = RelationData(output_path=self.config["output_path"],
sequence_length=self.config["sequence_length"],
num_classes=self.config["num_classes"],
num_support=self.config["num_support"],
num_queries=self.config["num_queries"],
num_tasks=self.config["num_tasks"],
num_eval_tasks=self.config["num_eval_tasks"],
embedding_size=self.config["embedding_size"],
stop_word_path=self.config["stop_word_path"],
word_vector_path=self.config["word_vector_path"],
is_training=is_training)
return data_obj
def create_model(self):
"""
init model object
:return:
"""
model = RelationModel(config=self.config, vocab_size=self.train_data_obj.vocab_size,
word_vectors=self.train_data_obj.word_vectors)
return model
def train(self):
"""
train model
:return:
"""
gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.9, allow_growth=True)
sess_config = tf.ConfigProto(log_device_placement=False, allow_soft_placement=True, gpu_options=gpu_options)
with tf.Session(config=sess_config) as sess:
# init all variable in graph
sess.run(tf.global_variables_initializer())
current_step = 0
for epoch in range(self.config["epochs"]):
print("----- Epoch {}/{} -----".format(epoch + 1, self.config["epochs"]))
for batch in self.train_data_obj.next_batch(self.train_tasks):
loss, predictions = self.model.train(sess, batch, self.config["keep_prob"])
label_list = list(set(batch["labels"]))
acc, recall, prec, f_beta = get_multi_metrics(pred_y=predictions, true_y=batch["labels"],
labels=label_list)
print("train: step: {}, loss: {}, acc: {}, recall: {}, precision: {}, f_beta: {}".format(
current_step, loss, acc, recall, prec, f_beta))
current_step += 1
if current_step % self.config["checkpoint_every"] == 0:
eval_losses = []
eval_accs = []
eval_recalls = []
eval_precs = []
eval_f_betas = []
for eval_batch in self.train_data_obj.next_batch(self.eval_tasks):
eval_loss, eval_predictions = self.model.eval(sess, eval_batch)
eval_losses.append(eval_loss)
eval_label_list = list(set(eval_batch["labels"]))
acc, recall, prec, f_beta = get_multi_metrics(pred_y=eval_predictions,
true_y=eval_batch["labels"],
labels=eval_label_list)
eval_accs.append(acc)
eval_recalls.append(recall)
eval_precs.append(prec)
eval_f_betas.append(f_beta)
print("\n")
print("eval: loss: {}, acc: {}, recall: {}, precision: {}, f_beta: {}".format(
mean(eval_losses), mean(eval_accs), mean(eval_recalls),
mean(eval_precs), mean(eval_f_betas)))
print("\n")
if self.config["ckpt_model_path"]:
save_path = os.path.join(os.path.abspath(os.getcwd()),
self.config["ckpt_model_path"])
if not os.path.exists(save_path):
os.makedirs(save_path)
model_save_path = os.path.join(save_path, self.config["model_name"])
self.model.saver.save(sess, model_save_path, global_step=current_step)
# inputs = {"inputs": tf.saved_model.utils.build_tensor_info(self.model.inputs),
# "keep_prob": tf.saved_model.utils.build_tensor_info(self.model.keep_prob)}
#
# outputs = {"predictions": tf.saved_model.utils.build_tensor_info(self.model.predictions)}
#
# prediction_signature = tf.saved_model.signature_def_utils.build_signature_def(inputs=inputs,
# outputs=outputs,
# method_name=tf.saved_model.signature_constants.PREDICT_METHOD_NAME)
# legacy_init_op = tf.group(tf.tables_initializer(), name="legacy_init_op")
# self.builder.add_meta_graph_and_variables(sess, [tf.saved_model.tag_constants.SERVING],
# signature_def_map={"classifier": prediction_signature},
# legacy_init_op=legacy_init_op)
#
# self.builder.save()
if __name__ == "__main__":
# Read the input information by the user on the command line
parser = argparse.ArgumentParser()
parser.add_argument("--config_path", help="config path of model")
args = parser.parse_args()
trainer = RelationTrainer(args)
trainer.train()
================================================
FILE: reviews/english
================================================
i
me
my
myself
we
our
ours
ourselves
you
your
yours
yourself
yourselves
he
him
his
himself
she
her
hers
herself
it
its
itself
they
them
their
theirs
themselves
what
which
who
whom
this
that
these
those
am
is
are
was
were
be
been
being
have
has
had
having
do
does
did
doing
a
an
the
and
but
if
or
because
as
until
while
of
at
by
for
with
about
against
between
into
through
during
before
after
above
below
to
from
up
down
in
out
on
off
over
under
again
further
then
once
here
there
when
where
why
how
all
any
both
each
few
more
most
other
some
such
no
nor
not
only
own
same
so
than
too
very
s
t
can
will
just
don
should
now
================================================
FILE: reviews/eval/books.t2
================================================
casual book browsers who stumble across braden book , " isaiah effect , " might undoubtedly drawn implications title : there exists some mystical , unifying code which only now fully understood through modern techniques , research , understanding . i , one such browser , briefly read so-called " bible code " which computers now enabled man explore thought subject this book might related . my interest piqued title book description , i delved into pages expecting learn exactly what encompassed isaiah " precise instructions " prayer . i wanted know exactly what braden claimed stumbled upon . what i found this 250 page foray into countless subjects nothing other than pastiche new-thought concepts . mixing religions , example - sort pick-and-choose spirituality which slowly creeping its way into mainstream decades - recycled over over again , drawing endless sources gnostic gospels other lost books . only one chapter braden actually begin describe detail verses book isaiah . instead he relegates books essenes positions higher authority prominence . brief pages which braden actually discuss isaiah , his conclusions speak nothing decoded lost science . his basic premise " effect " people alter their futures choices they make present . such revelation not new interpretation isaiah all . any student bible christianity knows all prophetic books old testament records god warning israel , world , turning away him . braden credit , his discussions effects prayer today society commemorable , albeit somewhat misguided . i agree him people today society need turn away petty details life which they've surrounded themselves . however , i believe braden over-emphasizes role feelings emotion prayer . he fails discuss how humans , their emotions , extremly fallable change quickly winds his anecdotes . braden wants desperately believe true power prayer found all lost science which he uncovered ancient texts . process he fails recognize blueprint prayer known man ever since he created . humbleness before god filling holy spirit true keys prayer - not cosmic emotions human feelings . disappointing read 1
refreshing look software development many pitfalls you need avoid . this book should read everybody involved any software project but simplest . my opinion , standard work . nevertheless , it needs handled care . during ages , sw development managers tried convincing their people break out chaos , plan their work . this book correctly warns opposite effects believing planning solves everything . some people might however read lines no planning all best practice . book confirms what i my successful colleagues found through experience intuition : there optimal point planning upfront . less harms because you don't know where you going , more ( too detailed ) harms because it takes away flexibility it slows you down significantly . new me use queuing theory point out what we see every day : too many features , under-resourcing leads far bigger delays than human mind ever guess . 1
so many books market pregnancy focus medical aspect what growing your wife little belly , not how little thing changing your wife life forever ! this book describes ' ' how this life changing event reeks havoc everyone involved process , it it way bust-a-gut funny . before i read this book , i like " what heck wrong my wife ? " after reading this book , i more like " ohhh , i know why she just ripped my head off ... she hates smell carrots ! " great book , fast fun read , must read new dad . i've bought it every father , they turn same . 1
aware reviews book displayed not only one edition , but all editions under same title . oxford philosophical texts edition hume " treatise " should standard student edition . prometheus books edition cheap , but it not include modern introduction or any study notes . i recommend oxford philosophical texts version if you want or need more than just raw text 1
it doesn't sound like people you list reasons " not " read this book , actually read " this " book . there big difference , my opinion , putting positive affirmations your mind , versus witch doctor . quite honestly , it seems positive affirmations could should used " conjuction " medical care . it say anywhere book forego medical care , because you most definitely healed ? no where . so my opinion , one " sound " mind , not view book " cure all " all ills life , but rather positive way " enhance " your life . it just plain stupid avoid getting medical care , when you terminal illness , or any other illness matter . but according what i gather book , you use positive affirmations , " believe " you getting well , help keep yourself positive state , rather than filling your head negative thinking you never get well . studies aside this book proven healthy positive attitude mental outlook , wonders recovering patients , their medical care . your review not address any those people read this book , because two examples people you list , it apparent they didn't read book either , ( not sure what compelled you post here ? ) therefore you not qualified , my opinion , critique this book , they using apparently some form faith healing televangelist , they prescribe drinking snakes blood , too ? anyway , this book no way says forgo medical treatment if you sick , those , probably won't addressing their medical problem . positive affirmations power suggestion help you through your medical crisis ? i imagine it , ( studies prove it ) addition proper medical treatment . anyway , you might want actually read book , instead making comments what happened " so so " who didn't even read it or apply it , including yourself . 1
first let it said this book leads you believe he hikes whole trail ... he not . he hikes less than third . you dont find this out until 2/3 through book , which right when book goes passibly bad , ill effort fulfill contract . my conclusion this book he contracted hike trail his publisher , could not , stuffed remainder book verbatum history lessions whole cloth inserts useless statistics . others said this review forum . this book snide , highschoolish down right mean . i fail see " wit " his endless negitivity bashing . this book few funny parts , but i cant help but feel it huge exageration real events , mostly contrived fictional accounts which he uses air nasty comments . it so unbelievible places , you know you imagined tangent . dont waste your money or time . i am so happy i bought it 25 cents yard sale ! -1
i personally not see how this book could won newbery medal . while author portrays sibling rivalry effectively , only positive aspect this book . fact teenage girl protagonist crush elderly man disgusting presented not only acceptable but understandable . sara family also unsupportive her sulky jealous attitudes . her grandmother busybody consantly antagonizes family . sara twin sister gets all attention love , leaving sara starving parental care . finally , christianity portrayed harsh judgemental . this book could possibly acceptable adults but never children i would not recommend it anyone . i wasted my time this book : please don't waste yours . -1
this joke book suks . if i give it any star i want , i would give it -10 stars . i never actually bought it , but i borrowed it friend . i needed joke book my anouncements intercom every morning , it only lasted 3 days i ran out good jokes . some jokes arnt appropriate most them dont make sense . if your gonna buy joke book , dont buy this -1
i didn't especailly high hopes this book . i think there gradual decline quality hh books over years , this one brings it new low . basically , it waaaaaay too long . 850 pages , it monster read , slow one . that not always bad thing - sometimes if you like characters it nice just hang out your friends page after page . but not here . why it necessary describe detail exact movements treecat using sign language ? several paragraphs ? more than once ? why we given pages liturgy religious services ? i think i'd very small minority when i confess i quite like 1662 prayer book , though i can't quite work out why it would revived distant future when it out use here decades ! maybe it easy cut paste , got word count up . then there space combat - strength series , especially first three or four . but there rub - there only so many ways you describe spaceship blowing up . 11th book series i can't only person out there whose eyes beginning glaze over when we get battle sequences . but big problem - spoiler alert ! - way which weber solves love triangle we left last book . honor loves hamish . emily loves hamish . hamish loves honor emily . what ? it turns out there easy solution . after 400 pages agonising ( not mention most previous book ) it seems honor marry them both . bit outre ? seemingly not - apparently such arrangements fall well within accepted norms manticoran law custom . ( although we've never whiff this before . ) but what really gets me reason it didn't happen halfway through last book ( get this ) , gosh , o-o ne thought it . it seems o-o ne ever told mr weber if you shoot someone gun act , gun better hanging wall act i . all-in-all , i only say , please mr weber . it time bring series end . please it soon -1
ivalooshun skary . i red bibel . bibel saez ivalooshun bad . ivalooshun shud go away . i red wer sumwun saed werld goez arund sun but lie . luk ski yu see sun goe arund werld . monsters skary . monsters shud goe away -1
" ... minus several million good thinking ... " - zaphod beeblebrox , hitchhiker guide galaxythe above quote ( score i've assigned this book ) aren't reference text or author , but publishers . why anyone brains sea urchin would cross professor hawking they seem beyond me . briefly , save your money buy illustrated brief history time instead theory everything , even if you're compulsive hawking completist . alert readers should notice hawking doesn't hold copyright theory everything , attempted block its publication . it originally titled cambridge lectures : life works , appears drawn some recordings lectures given professor years ago . ( see professor web site details . ) " vanilla " ( i.e. , not illustrated ) theory everything consists introduction , seven lectures , index , without * any * illustrations or diagrams . out curiosity , i compared library copy it illustrated brief history time . unless otherwise noted , each 7 lectures corresponds chapter same name brief history , some segments only slightly different paragraphing punctuation ( occasionally kind spelling errors creep when one transcribes audio narration text , if i may speculate cause ) . i don't understand why anyone would prefer less polished text theory everything illustrated brief history time , which not only updates new areas research , but revised rearranged explain things more gently layperson . " ideas universe " essentially extract " our picture universe " , first chapter brief history , one sentence worth drift per paragraph . brief history version " expanding universe " more gradual introduction methods measuring distances nearby stars , explains technical terms may unfamiliar non-scientist , such luminosity . theory everything really shows its age " black holes " when compared brief history , hawking not idle area over years . illustrated edition brief history fair bit interesting material added " black holes " , especially regarding cosmic censorship naked singularities ( hawking made few * more * bets subject preskill thorne , although he paid off cygnus x-1 wager ) . " black holes ain't so black " lacks major blocks clarification/explanation added hawking version brief history . brief history version " origin fate universe " goes into more detail : kinds particles predicted come out big bang , what sort results we'd expect see today if predictions hold , scientists who first put forward these theories . brief history also contains much longer version " open questions " section , leading more gradually up discussion guth development inflationary model . " direction time " corresponds brief history " arrow time " ( which worth picking up just picture keeper u.s. cesium clock ) . brief history goes into more detailed examples explain what hawking means psychological arrow time , simplest kind " computer " : abacus . " theory everything " mainly corresponds brief history more modestly titled " unification physics " , which much more up date ( string theories still covered , but lot more work area over years ) . tail end lecture corresponds ending brief history " conclusion " . -- summary , this interesting stuff , but illustrated brief history time it better -1
herf applies very simplistic test determine nazification both germanies : they side israel middle east version cold war or they not ? trial against paul merker east , which its background east germany reluctance pay reparations expropriated jews , serves his prime evidence continuation things nazi gdr . but both these arguments completely ignore marxist ideology underlieing rationale east german leadership bypass more complicated issues political allegiance . moreover , they totally eclipse east german cultural discourse holocaust , discourse decades ahead discussions west still proves more sophisticated than most written western academia . -1
i loved this story !!! action fast-paced romance sizzles ! buy this one nd then buy few copies friends they glad you !! 1
book #9 death series . this one my favorite books series . this book while eve peabody investigating murders organ thefts victims , they come across cop attitude . after eve gives this officer dressing down record , officer writes complaint . when officer turns up brutally murdered , eve asked give up her badge while investigation underway . you very dynamic story line . while eve inner circle support her she still struggles what life would like if she can't cop . there some very emotional heartbreaking scenes . also very funny one when roark gives her some ideas alternate " jobs " . excellent book you wont want put it down ! we meet troy trueheart this book some secondary characters really shine 1
i can't say enough good things reef ! it shows strong female character field used dominated men , strong sensitive male isn't afraid dream . this fantasy come true involves marine archeologist tate beaumont matthew lassiter their families . families run into each other while treasure-hunting angelique curse - treasure eluded everyone , many think it only myth . but this artifact worth everything some , even worth killing . this joint expedition continues , it holds all elements needed great story : mystery , romance , secrets can't shared , deceptions threats . there so many angles could pursued reader isn't sure which avenue nora roberts take until she delivers them it . this always keeps you edge your seat , gives you first hand " view " undersea world beauty intrigue . i highly recommend reef only wish it would continued - or least sequel works ! great characters fantastic plot hook reader beginning . one nora roberts better works ! 1
this book so boring i could barely stand it . fact , i abandon ship halfway through . main character kind interesting , two kids , but story itself so slow-paced characters can't carry book . i am huge reader i count one hand times i've quit book midway , but this one just couldn't hold my interest . i found myself daydreaming everytime i tried read it . writing over top ... author sounds if she writing try get award rather than tell story . pretentious readers may try act like they enjoyed this mess , but don't believe them . one worst books i've ever read -1
" how " guide understand corporate america . very clear , easy read fascinating . love it 1
there plenty good summaries this book here , so i'll briefly make one point : this book good read , but business climate changed dramatically since it written , many characters here retired or moved very different investing styles . so book worth reading , but i'm not convinced it timely say lowenstein books internet bubble or hedge funds , or any many enron books out now 1
you ever desperately wanted book end but hated leaving it unfinished ? that way sappho leap me . i finally finished it over weekend am still wishing i hadn't spent good money , even bad money , any money it . admittedly , very little known only ancient greek female poet besides where she probably lived few snippets her poetry . her words searing , lovely sometimes erotic . but erica jong novel fictionalizing her life banal boring droll . sappho , her heroine not only uninteresting , but no single aspect her personality makes me like her . sure , she experiences heartache longing , but jong simply fails give me reason care . jong just tells me , flatly , first person , how sappho feels what she thinks , but doesn't make it real me . she tries make sappho into female odysseus can't figure out if novel should fantasy or semi-believable historical account . all wrapped up very disappointing , hollywood ending , tied it off into unequivocal piece garbage . i can't believe erica jong actually written published eight novels . it honestly seems like she wrote sappho leap specifically sell high school english departments teach bit greek history feminist slant . regardless whatever pocket genre she trying exploit , sappho leap utter tripe -1
i delighted how immediately useful this book ! within day it dog-eared , highlighted bristling sticky notes . dr steven miller i now putting final touches our ebook : " bully trap " we really used " writing nonfiction " great resource throughout . dan book lays out clear simple strategy entire project ! thank you , dan , such gem ! 1
very good easy use ans carried you 1
caro definitely authority lays book out way easy follow . he explains concepts , includes photos , reviews " laws " tells offers quiz end book . answers quiz include where check if you missed question . i definitely reccomend this book . it written better than some textbooks 1
i really enjoyed this book refer back it still . it full great examples what talked , uses language easily undersood awesome photos well . great learning tool 1
mehrling(m)has written engrossing biography black . shows black understanding capital asset pricing model(capm ) , which based treynor multiple risk factors approach , emphasizing importance using covariance relevant group stocks appropriate measure financial risk , opposed sharpe -lintner version capm focused variance individual assets(stocks ) , served foundation practically all black ideas finance economics during his lifetime . what left unclear reader whether black moving direction . . keynes . ellsberg able clearly differentiate risk , based assumption normality concentrating measures like standard deviation , variance , covariance , instance , exemplified black " universal hedging formula(see pp . 183-184 ) " , ellsberg concept ambiguity(keynes concept uncertainty general theory weight evidence treatise probability ) . very suggestive black possibly moving this direction , given black use literary terms such radical uncertainty , indeterminancy , nonstationarity , where change technological advances so prevalent it would impossible use any probability distribution specify outcomes . black support " new " behavioral economics , emphasizing actual financial decision maker reliance all kinds rules thumb heuristics la tversky kahneman(r shiller irrational exuberance , instance ) also would appear lend support this possibility . unfortunately , there no actual technical evidence demonstrating this possibility black academic business articles . there no extant , explicit treatment clearcut uncertainty(ambiguity)versus risk distinction made corpus black work . this leads my assessment black come realize assumption normality , upon which all financial economics currently based , incorrec t.t his pointed out early 1960 benoit mandelbrot . one need only look any paper or book written . fama visually note shapes probability distributions price changes different markets not normal , but cauchy . one ask embarrassing question - " why no test goodness fit(chi square , instance ) performed and/or replicated/duplicated before finance economists 1960 1970 decided making assumption normality foundation their efficient markets hypothesis , capm model , black-scholes equation , etc .? fact mandelbrot demonstration appropriate risk concept wild risk cauchy distribution not mild risk normal distribution financial markets all developed countries means advanced capitalist countries fact unstable , boom-bust economies not stable , convergent economies classical neoclassical economics . uncertainty-ambiguity analysis keynes ellsberg leads same conclusion . schumpeter view economy subject " creative destruction " based " regular irregularity " occurrence technological change advance would also certainly fit nonstationary views time series data expressed black . black work certainly deserves read . however , he lags behind ellsberg , keynes , mandelbrot , schumpeter original thinker . 1
i saw play san francisco few years ago . it very funny . bit aa members running restaurant very tongue cheek 1
this solid work subject matter valuations . although it definitely academically oriented rather than telling than story , it gives great examples ( many them based real-life deals ) actual real-life applications . plethora examples solid coverage area earns this book permanent spot my bookshelf . i believe i'll referencing it quite often . also , included cd helpful sample deal models immediately usable . side note , i find no basis ' one-star ' review ' mba-student ' hoping gain some insights before interview investment bank . comparing arzac solid work reviewer misleading comments raises questions reviewer competence and/or credibility 1
after janet fitch phenomenally successful book " white oleander " readers waited baited breath next novel . after several years , here it : " paint it black . " those who loved " white oleander " no doubt enjoy fitch long-anticipated novel , which focuses josie tyrell , tough , independent bleached blonde bakersfield who scraping living los angeles . when novel begins , josie , artist model avant-garde film actress , shares small house rundown area los angeles michael faraday . artist michael currently away his mother fancy family mansion working art project -- well least that story he told josie , but josie gets phone call coroner office michael committed suicide motel twenty-nine palms . while trying cope aftermath michael death , josie begins realize some things just don't add up suicide . example , michael told josie he couldn't drive , yet he drove rented car motel where he found dead . josie attends michael funeral here she meets michael divorced parents -- writer cal faraday--who remarried new family , michael mother , concert pianist meredith loewy . while michael mother attacks josie gravesite , cal shows vague , generalized kindness , but when josie discusses michael cal , it becomes obvious josie michael wasn't entirely honest himself . suicides always leave those left behind questions , but michael case , josie finds herself knowledge there seem two michaels -- michael she knew loved , confident , athletic , affluent society michael faraday , only son rich , famous parents . aftermath michael suicide , josie struggles her memories while trying make sense past year her life -- turning alcohol narcotics blunt her pain . then controlling ice-queen , meredith loewy enters josie life , two women -- two who loved michael best who struggling survive his death -- form uneasy relationship , dangerous , destructive seductive game cat mouse begins take place .... " paint it black " proves author janet fitch phenomenal talent here stay . josie , fitch once again created tough , independent , unforgettable female character -- woman who survive spite odds against her . josie case , she raised one large , poor family bakersfield , while she part la punk scene , she also undeniably drawn ease elegance meredith privileged world . " paint it black " , fitch matured writer , she honed her skills . when it comes description , unforgettable characters , power evoke immediacy emotion , fitch cannot faulted -- displacedhuma 1
if you new field pricing this book help you start asking some right questions how establish pricing system your organization . those you some experience field already it draw you attention again fact price differentiation much larger impact than statistical price optimization . book full fun examples quick read 1
i recently attended nanobusiness 2004 new york city -- cost $800 plus hotel travel ) . i could saved all money just investing this book beforehand -- it literally covered 95% information provided conference speakers . if you considering learning more nanotechnology , i strongly encourage you start here . book very easy read ( especially non-techies ) it provide you excellent foundation 1
this book made me start thinking my health problems . i would recommend this book 1
cheap mixture basic body language knowledge psychology catered masses . very shallow some its comments show unbelievable degree narrow-mindness ( comments like " if you look like this , you like " all over book ) . very disappointing book , comments like " if someone speaks sports lot , he probably likes sports " ( page 63 ) say it all . 1
this marvelous volume enjoyed book photography lovers alike . object its own right it exhibits level refinement conception execution become rare our age mass-produced books . course , there many specialist photobook publishers but they seem focus exclusively print quality increase perceived value their publications , whilst neglecting vital contribution design book overall appearance ( desirability ) . phaidon-volume , exquisitely judged rhythm layout typography complement vivid reproductions vintage photobook material into very exciting whole . sure , care spent production this book not gratuitous . contrary , it statement reinforces basic conceptual tenets held badger parr . introductory pages we learn not every any book conceived around collection photographs merits included class " photobooks " . photobook - badger parr understand it - more than just sum its parts : pictures , words , design , choice subject all contribute something which transcends meaning photographic portfolio . this all illuminating one could certainly say " photobook " instructive example this synergy various elements . however , i wished editorial team would left it . i think badger parr moving onto much more controversial ground when they hold forth emblematic photobook kind dramatic event , " comparable piece sculpture , play or film " which individual photographs lose their own character things themselves . apart theoretically doubtful , i believe this criterion simply too stringent many vintage photobooks featured this survey not comply it . example , many early books photo albums true sense word : bound collections original prints glued onto white pages . similarly , it difficult see some modernist books - such erhardt " das watt " or mendelsohn " amerika " - anything more than expertly produced photographic portfolio . each these examples there coherence , but it not derive some kind dramatic or narrative logic . it simply unity style which holds photobook together . positioning photobook " novel film " , therefore , raises more questions than it provides us answers . it doesn't really help make sense " ragged sprawling subject , more than its fair share anomalies " . it perhaps more useful investigate how badger parr tried organise their material within confines this volume ( next ) . they seem relied three different lines thought . first chronological ( it history after all ) . survey starts very first publications , early history photography end section " photobook modern life " . this sense , book studied remarkably lively varied panorama how photographers engaged their craft over last 150 years . second organising principle geographical : some individual chapters focus distinct area cultural production ( us , europe japan ; next volume features chapter " worldwide photobook " ) . finally , there " intention " structuring element . photobooks produced serve variety purposes : tell story , tell non-story ( stream-of-consciousness-like books ) , non-tell story ( deconstruct ) , document , persuade , etc . indeed , valuable photobook even limit itself simply showing . most chapters two volumes put some kind " intention " center discussion . i think badger parr conception their own book certain extent odds their conceptual emphasis dramatic nature photobooks . if there drama " photobook " , it mediated words accompany various chapters , not visuals . other words : it conceptual not photographic narrative unfolds . regards visuals , curiously enough daring use white space drop shadows around book page reproductions really make them stand out preciously unique . leafing through book akin walking carefully presented museum exhibits . this sense , " photobook " clearly `shows ' , therefore pulls us away dramatic sweep history . despite these theoretical misgivings there not shade doubt my mind this book deserves five stars . it fabulous book i look forward keen anticipation second final volume . 1
since there already 250 reviews this book , i am just going say earlier portion book may contain very best english-language prose style ever written -- even better than joyce nabokov ! oh , also , pynchon not only robbed pulitzer prize , but also ( so far ) highly deserved nobel prize ( also true john ashbery ) 1
i imagine my mind what it would like coffee luis borges sunday afternoon . borges would wearing suit little cakes hand , cane leaning his armrest , if nothing out ordinary occur . labyrinths useful first book kick off lifetime investigation into borges ' writings . borges truly original author much his intent his achieving it . not quite magic realist , not quite existentialist nor kafkan : no one borges ' equal taking established assumptions turning them into curious , elaborate , eruditely-supported flashing crossroads defy simplification . even most unassuming essays like " fearful sphere pascal , " subtle historical resketching , characteristically erudite , yet sticky complicate subject irresistibly your first reading onward . prickly thorns reach out your existing education subject designed flesh out glaring inconsistencies you read subjec t.t he garden forking paths example prime borges storytelling work . story itself ruse . first reading-through not time you affected most borges , but rather only after you put book down , when borges ' physics begin gnaw your world compact , necessary daily conveniences , even 2005 when we really ought intimately familiar his universe now . i think ultimately borges sets tiny mind bombs set detonate exactly time you seek superimpose newtonian universe upon one his stories , ultimately , later , when you seek superimpose order upon your own human experience . entrance seems same , but it clearly moved time you exit story . you become part puzzle , bedazzling signature borges , his unassailable virtue . everything solid universe daily lived experience becomes compost peacefully unsettled , it originally , before we came fix it up like morticians just before funeral . 1
freedom better goal than gdp . this book describes new concepts presents important , controversial , conclusions . concepts relevant developed developing countries . foundation sen view well-being formulated follows : " we all want capability live long ( without cut off our prime ) good life ( rather than life misery unfreedom ) " " we would all like lead kind life we reason value " . achieve goal requires removal unfreedoms like poverty , lack ability accepted job , lack economic opportunities , health problems , discrimination , repression arbitrary justice . freedom end itself means able lead satisfactory life . individual freedom also condition able act responsibly . without opportunities because lack capability , no responsibility . increasing freedom goal more complete than increasing gdp per person . people good reason want income wealth precisely because it " produces " freedom . gdp/person freedom related . when people act responsibly because they capabilities find job , gdp increase automatically . . book very rich " surprising " conclusions all convincingly documented presented . only few referred here . ( 1 ) important cause poverty sub saharan africa south asia explosive population growth . if women freedom decide number children explosive population growth stops . there no justification using violent means reduce family size . ( 2 ) all poor countries afford basic healthcare basic education these labour intensive therefore low cost . ( 3 ) opinion democracy free speech elections not suitable asians because different asian values no factual basis . ( 4 ) one fundamental freedoms people cherish buy what they want whom they want sell what they whom want , " free market " . idea free market left alone function perfectly it based self-interest greed false . it requires effective legal structures support rights ensuing contracts , people trust each behave decently . sen warns danger " high minded sentimentality , assuming all people peculiarly virtuous keen just " or equally unrealistic " low-minded sentimentality , which some economists appear prefer , we only influenced crude consideration personal advantage " . free market " function requires freedom , regulations ethical values beyond greed self-interes t.t he book brilliant but requires effort read . read least chapter 1 perspective freedom , 6 importance democracy , 9 population , food freedom , 10 culture human rights 11 social choice individual behaviour ( 100 pages ) . 1
i read works folks like vince flynn , lee child , , i thought , nelson demille , escape -- action -- intrigue . someting make plane flight go faster . i don't read thinly-veiled , current-events , quasi-political commentary . ( there recognized exports available sort thing . example , tour-of-duty vietnam gives neither me , nor nelson , " expert " status conduct warfare . ) demille , he matures person writer , taken slipping his " agenda " into his storytelling . consequently , " story telling " aspect his craft , my opinion , atrophied . he , course , right . but i , one , am reading his books . there always news if i want current events commentary . better suspense writers if i desire entertaining escape . -1
only problem even though it only penny you'd still pay $2-$3 shipping . not worth it ! funny book written sweaty little fat kid crazy christian conservative parents . hearing 14 year old virgin boy opinion abortion great . it all yours only one penny -1
i found this book very complete comprehensive reference source . it covers strategic operational perspectives finance function . this one best quot ; cfoquot ; books , together quot ; cfo architectquot ; quot ; cfo handbookquot ; . little bit overpriced - i would put it us$60 range . reading this book like taking advanced course preparing yourself cfo career . it very didactic straightforward . recommendation author : future edition , you might consider expanding topics international finance , value based management corporate restructurings 1
ok , so maybe fowl series not exactly lord rings caliber , or even harry potter level . but it enjoyable read if you take it what it . sure , it directed towards kids , but this 42 year old kid heart blew through it couple days , plans likewise next two series . you'll enjoy it too 1
david mills ' " atheist universe " lucid presentation rationalist viewpoint nature our world how it explained without resorting mysticism unprovable assertions supreme . it , mills carefully lays out reasons why we needn't assume existence god ( or gods ) understand natural phenomena , demolishes numerous assertions teachings religious spiritualist propagandists . his primary target christian fundamentalism , but he makes it clear his critique religious beliefs equally applicable other faiths well . places , his explanations get bit technical , but he fine job demolishing pseudo-scientific mumbo-jumbo used " intelligent design " crowd their fellow travelers . ( chapter internet porn , however , seems out place . yes , biggest porn-bashers often religious conservatives -- but so what ? what validity atheist viewpoint ? )one thing i particularly enjoyed numerous quotes past present thinkers mills includes throughout book . among those he cites albert einstein , thomas jefferson , thomas edison mark twain - numerous others whose writings i long admired . " atheist universe " probably won't convert many diehard religious believers , but if you all open-minded , qualms endless barrage religiosity engulfing america today , this book well worth buying reading 1
i really liked first one even went my mom house pick up second one ( this ) 10:30 night right after i finished it because i so pumped read . get go i could not get into this book i force myself get page 120 . not much happened make me want finish it . very boring . not really into roz mitch characters , i don't think they very well developed , they seem kind blah . story kind blah . blah , blah , blah , just words blah , blah , blah going . -1
this book not flowery soft . there parts i thought i could not read , not want read . but this book great plot before you know it , you hooked end . cannot wait until ms. flynn next book 1
why title " right man " ? i didn't get it . what so right bobby dallas ? he typical black man imo . he ended up great job salary only then he decide he ready settle down faye supposed it . not ! he played couple different women , dishonest , less than " right " . i only finished book because i spent my hard owned money it . this book entirely too slow . it like , please get point omar tyree . after this , i believe i am finished supporting him his less than stellar novels . i only wish i hadn't spent money black man writing how hard it black man out there dating professional world when i get same sob story any local hangout . save it save your money ! 1
mr. bawer makes distinction those christians who want emphasize god love ( " there ain't no hell " group ) those who want emphasize god law ( " hell there ain't " group ) . i think fundamentalists all brands ripe exposure bawer raises some very valid points . most fundamentalists i know quite nice people . unfortunately , when idealism gathers groups , mob tends form , regardless dogma . large enough mob start war . if one goes down block , across nation , or around world each church , synagogue , mosque or holy place , some fundamentalists each theology may found . each sub-group irritating habit thinking their group alone , once all , solved great riddles life . it seems me , amongst all varied dogma , there only one way any one them or all them right ; extent which group teaches theology tolerance love . 1
if you developing fresh talent , then you need this book . i used this countless lesson plans when teaching my people fundamentals selling . this close " required reading " you find . gitomer ultimate sales guru because he keeps things simple . he doesn't teach how sell , he teaches you how show value so people buy . bible beginners many ways so if you've around block enough know way , skip this one grab one his red books or patterson principles . they more experienced sales professional 1
great bible study book . we learning lot great time it 1
this book isn't masterpiece , but it tell story one america best pilots . it tells life bob hoover his eyes . stories he tells almost unbelievable ! it very entertaining book , i could hardly put it down , i would recommend it anyone who interested aviation , especially those who like hear great stories how aviation changed over years 1
i bought my first copy this book several years ago . even experienced dog owner , i learned lot ! since time , i've bought 5 or 6 books give gifts family friends . my opinion , it best basic dog training ( or should i say , owner training ) book out there ( i've read most them ) . concise , yet full information 5 stars plus ! 1
i think very informative . i actually share some experiences someone else . it perpared me future experiences i might come contact 1
this refreshing read i really enjoyed every minute reading it . its not life-changing sci-fi but its fun story great characters . i highly recommend this one sequel they tons fun 1
i keep this book right next experience economy pine gilmore my desk next computer . pink super job outlining some valuable business trends . right-brain phenomenon value business real . it worth read anyone seeking business training but not sure where turn next . there some real-world exercises book . paper-back version even more these . 1
my 8.5 mo old son finds this book so enticing i can't leave it lying around , he makes excited noises every time i turn page . he no mild interest most other books . only negative many adult readers stumble over chongo chingi name . i think odd detail illustrations likely hold interest older toddler or preschooler too , unlike most books suitable small babies . i like offbeat style which refreshing change so many pastel or primary colored children books 1
when you arguing whether or not christ really existed ( words stuart briscoe possibly others ): if man believes christ lives his life accordingly , he wrong , then he lost nothing . if man doesn't believe christ lives his life accordingly , he lost everything .. -1
it no secret children today wield more consumer power than ever , marketers discovered them one most profitable niches . but what real impact all this consumer attention children ? her latest book , renowned economist , consumer/family studies expert , founding new american dream board member juliet . schor argues this impact detrimental , something we ought paying much more attention . says schor , " we become nation places lower priority teaching its children how thrive socially , intellectually , even spiritually , than it training them consume . " indeed , her documentation commercialization within schools truly disturbing . results survey which schor administered sampling " tween " -aged children strongly indicate heavy involvement consumer culture jeopardizes children well-being . ultimately , schor argues we need take steps decommercialize childhood , she lays out several intriguing ideas how so . highly captivating packed vivid examples , this book should required reading not only parents but anyone who cares future our society . 1
me talk pretty one day one-third amusing , one-third funny one third absolutely laugh out loud hilarious . whether retelling story his cussing brother , his experience speech therapist or class non-native speakers french trying explain easter classmate , david sedaris knows exactly what focus hit person right funny bone . although two his previous novels , barrel fever dress your family corduroy denim , contain stories similar themes , they not nearly funny , maybe due their tendency toward more restricted/adult themes . those who plan give david sedaris ' humor try should choose this one 1
book came quickly great condition . would use this seller again 1
" neoconservatives boat people mcgovern revolution itself political vehicle moral , social , cultural revolutions 1960s . " key understanding neoconservatism it not sibling or " update " traditional conservatism . see it way only mislead you . neoconservatism roots sprouted left more than right . current gop " may reaganite its tax policy , but it wilsonian its foreign policy , fdr its trade policy , lbj all way its spending policies . pragmatism order day . republican philosophy might summarized thus : " hell principle ; what matters power , we it , they not . " but when one becomes one enemy , who won ? conservatives nationalists . neoconservatives internationalists . conservatives protectionists . neoconservatives free traders . conservatives see culture war essential . neoconservatives see it distraction . conservatives believe defending land militarily project our ideals example . neoconservatives believe defending it offensively projecting our ideals force . neoconservatives presidential candidate george . bush match domestic policy 2000 ( bush didn't propose single spending cut his campaign ) , but it appears they hijacked his foreign policy , whatever it used . ( given events his presidency , it startling reminder this same president couldn't name four world leaders when he quizzed during 2000 campaign . ) foreign policy defense advancement world democracy , something never america aim . only proactive foreign policy we've ever truman doctrine , stance we took when soviet menace showed itself aggressive real threat united states , our allies , our real interests . clinton interventions , misguided they , least brief limited , nothing risked expansion into long-term , regional conflict . same cannot said iraq . mr. buchanan gives chapter-length history islam europe , setting scene 9/11 . following war afghanistan just necessary , quite diplomatic masterpiece , one could foundations better relations middle east , which shown considerable support our efforts against al qaeda . iran , al qaeda enemy , voluntarily offered help afghanistan , but bush soon after named it among " axis evil " . neocons attached their agenda unclear war terror advance war iraq , war neocons pursued years , followed frightening series wars throughout region . war terror evolved into quest worldwide democracy , buffered moral imperative our diseased culture violates almost every way , unrealistic belief middle east wants democracy , even though they've never chosen it themselves . mr. buchanan also offers study terrorism , what touchy thing it : weapon weak , reaction empire , stuff martyrdom . new bases central asia , invasion iraq , talk much more war , neocons starting frighten world . china , now surrounded u.s. bases , began building tailoring its military our encirclement , leading all-offense neocons believe war them could expected , even though their going war us would suicide . china wasn't just preparing us : it reacting us . neocons reacting world their own making : filled nations wouldn't war us if they democratic . this utterly divorced conservatism , historic american foreign policy , moral , constitutional , realistic restraint . perhaps it best long term iraq didn't turn out ; madness seems coming end . even neocons seem believe failure now option . mr. buchanan then turns domestic issues : disaster free trade , continuance big government , imperial judiciary . however , all you'll find neoconservatives problem sense they're not solution . cultural issues given them plenty chances fight solidify their base , but they've silent , often quick fund whatever nonsense demanded funding keep issue open debate away hands democrats . neoconservatives seem concluded big government gets votes , social issues distraction . but culture war truly began horrid warren court , while congress didn't use its constitutional power hold it back . neoconservative gop seems too focused bad foreign economic policy concerned judicial usurpation power it wasn't meant . neoconservatism hasn't corrected wrongs ; it created more them . i hoping some answers overall question i've neoconservatism : where all this going ? how massive debts get paid when spending out control manufacturing sent overseas ? where peace begin after perpetual war ? mr. buchanan doesn't offer anything here but question . perhaps that neocons themselves . perhaps even they don't know . " where right went wrong " could prequel " state emergency " this book good summary bush first term , whereas latter defines pressing issue second . however , this book includes afterward , written early 2005 , summarizing voters ' response electric 2004 election , defining battle lines within gop traditional conservatives neoconservatives , fighting which began almost soon 2004 returns 1
student many books , i safely say this offered less information subject title any book i read . it made me little hesitant new books unless i specifically know author . spend your money elsewhere -1
it simply unbearable put this book down . character development completely captivating ; humor eve roarke regarding childbirth cannot but keep reader chuckling . great thriller great story outside thriller . masterpiece inside masterpiece . i say no more so would ruin pleasure reading " born death " . would unspeakable crime 1
excellent book . clear figures . however , this book same problem most medical texts , namely too long . review book i would expect something much shorter , but that not exactly fault authors since biochemistry pretty big field . but current length , i would recommend reading book marks marks smith since it only couple pages longer it more useful information ; i.e. it book you use during your second year pathophysiology courses . review i would recommend new text rapid review boichemistry simply because it short point , only high yield information , cd full questions . however , lippponcott still very good book probably used your only resource biochemistry medical school if your school follows standard medical biochemistry format versus clinically oriented biochemistry class , which requires supplementing other texts or lecture notes 1
excellent book , definitely great resource anyone looking expand their horizons respect critial thinking logic , grammar , rhetoric . this must read those looking add some depth their knowledge base . 1
this book not all what i expected brands , who pulitzer prize finalist his biography benjamin franklin , first american . trying make academic biography accessible reading public , brands ' writing suffers greatly becomes far too colloquial . one point , when discussing indian-white relations , he goes so far call whites " palefaces . " it chore get through , while it heightened my knowledge jackson , nothing particularly memorable except what i already knew or , perhaps , actions i disagreed ( his invasion florida or his use martial law after battle new orleans ) . particularly when discussing jackson historically far reaching actions , such kicking cherokees out georgia , or his battle biddle eventual destruction bank united states , brands deplorable job explaining what happened . elements background , why jackson whatever it he exactly , reader confused point , conspicuously missing . i read similarly poor reviews biography brands , tr : last romantic , if first american all similar style , i know why he didn't win pulitzer -1
am i only one who didn't get complete book ? first i noticed there some poor editing - lots typos . but then after page 180 , where page 181 should ( sleep chapter ) , it goes back page 117 ( discipline chapter i already read ) . it continues repeat pages 117 180 ( whole 63 pages duplicated ! ) , then picks up again page 245 middle school days chapter i don't beginning . i'm completely missing pages 181-245 ( 67 pages ) . other than , good few laughs handful ideas 1
laurence bergreen " over edge world " great example how narrative history should written . he takes very interesting but overlooked story breathes life into it . most history books magellan first circumnavigation merits few sentences or paragraphs , but brief mention conceals rich story underneath . magellan portuguese man who sailed under spanish flag , five ships began voyage , only one completed circumnavigation . magellan died during voyage , but not before facing two mutinies countless other hazards . bergreen excellent job telling this story . he explains nautical terms shipboard conditions early 16th century , he puts story into its proper political cultural context - time when inquisition still powerful force spain age exploration changing europe . my primary criticism book should many more maps ; it only included one map ( displayed twice ) entire world inside each cover . my only other criticism , others pointed out reviews , bergreen sometimes seems not understand -- or explain -- concepts like international date line . this history book reads like novel . bergreen brings out human suffering , triumph , failings during this voyage . it great read anyone any interest history . 1
i loved re-imagine . sometimes it infuriating . maybe design overdone or some ideas may re-iterated lot , seen diverse reactions book . but end i would just like quote machiavelli . " it must considered there nothing more difficult carry out nor more doubtful success nor more dangerous handle than initiate new order things ; reformer enemies all those who profit old order , only lukewarm defenders all those who would profit new order ; this lukewarmness arising partly incredulity mankind who not truly believe anything new until they actually experience it . " --- machiavell 1
reading this book , you get impression michael lewis just moved jim clark year . sadly , these direct interaction stories anecdotes not compelling more standard journalistic backstory : tale clark rise abject poverty , founding silicon graphics his eventual war management board there , story netscape . up date stuff less interesting , unless you really fascinated big sailboats . if we rating lewis books scale 1-5 , this would only rate 3 . but since other authors also fit into scale , this gets 4 .. 1
i like idea pocket book , but disadvantage you force your eyes read it properly . although it great info palmastry complete introduction ignorants topic 1
this quickly become part my daily devotional reading . format allows it used mini-worship service . date , however , i primarily used it suggested scripture readings wonderful readings various sources accompanying each weeks program . i like pattern multiple , brief readings versus single long offering 1
comedy audiences tougher customers than ever before , looking comedy avoids easy punchline takes them somewhere they didn't expect . squeaky clean comedy just : it mixes henny youngman standards fresh , new plo t-t wisting humor . ironic clean comedy braver than dirty jokes these days 1
i consider dr. radin man takes lot heat his experiments beliefs . whether or not you agree him , i think this book shows dr. radin didn't come conclusion psi phenomenon real overnight . he spent years investigating subtle aspects " psi phenomena " , analyzed large bodies this type experimental research , learned implement numerous statistical techniques . i not consider him " quack " . dean radin dedicated scientist . whether or not he misguided scientist depends upon your point view . i am not convinced he misguided . this book made me open investigating more learning more before i draw any conclusions . i simply am not sure what believe . dean radin very expressive easy read writing style . addition , he uncanny ability explain ins outs statistics utilizing simple analogies . me , this resulted book i able read digest very rapidly . i decided give book 5 stars all above reasons . potential psi research criticisms addressed reasonably well dr. radin include : 1 ) file drawer problem2 ) problem fraud3 ) statistical significance results ( ie . effect size)4 ) replicability results5 ) use meta-analysis6 ) sensory leakage7 ) randomization teststhere one area criticism i wish addressed more thoroughly : fair amount skepticism psi phenomena appears stem fact so much evidence based " statistical deviations " . granted , ( ) values important , but isn't there even one form psi captured upon demand ? not one ? how psi effect looked tangibly ? where ? i understand dr. radin point psi phenomena inherently complex , but there least one truly tangible demonstration its effects . after all , parapsychology very broad field inquiry . consider , instance , physicists actually conduct quantum teleportation experiment . it observed . nobody deny it anymore . enough effort , it visibly reproduced . psychologists give rat certain narcotic observe its unusual behavior . chemists form compounds , you view them microscope . i mean there come point where you actually isolate least one aspect phenomenon make it tangible . statistics inherently complex there so many confounding factors it easy skeptics dismiss results one way or . instance , i feel parapsychologists need find way create tangible demonstration psychokinesis so skeptics truly lost words . not tangible statistics , i mean truly tangible . personally , i would elated if any following happened : 1 ) large group psychics able bend piece metal even millionth inch under very tightly guarded conditions , experiment designed monitored deeply affirmed skeptics . psychics could try this many times they wanted until they produced effect . surely psychics could overcome negative experimenter effect , least once , given unlimited number trials ? 2 ) large group psychics able move very specific small electronic gadget certain small distance or alter very specific bit information while under extremely controlled circumstances . experiment would monitored skeptics . psychics could attempt this many times they wanted until they made it happen . i am confused why this type irrefutable evidence doesn't exist . or it exist , skeptics still denounce results ? am i missing something here ? there some visible , tangible , irrefutable evidence mainstream science would forced accept . i doubt mainstream science would reject such evidence . without directly isolating effect , making it tangible , skeptics always play hardball . right ? [ ... ] 1
if you enjoyed " soul new machine " tracy kidder , you don't want miss this one . it establish new benchmark , i think , much quoted books decade folowing its publication 1
this certainly best book i've read physics . it highly readable imo far more comprehensive comprehensible than briefer history time ( which its own right good book , but this more enjoyable read , contained lot more information instruction ) . what author , brian greene , particularly well use very effective stories analogies illustrate key points . i think i'll read his previous book , elegant universe , order get some hard science behind topics fabric . 1
i loved writing style this book -- very bright lively -- but book , me , too long because bitter , depressing sex scenes . franzen people really don't like themselves or other humans , ends up unpleasant . spite wacky humor , book really very dark . -1
this book covers history arabic world since pre mohammed times date . course , given length book , you cannot expect very detailed treatment nor depth analysis ( same author seems offer them other works ) . but concise first-approach history very useful . if you just need get facts , road map sense what history middle east , this very useful book . it short , fast read opens up your appetite more . it not answer questions but it something more important : it makes you ask lots questions 1
nice book i like it . just buy it 1
i lived el salvador now over eight years . visit el salvador three days continue make profit those three days -past- seems completely immoral me , especially since book remains print continues influence world opinion el salvador . i find this completely unfair . would it possible joan or oliver or anyone else enjoyed income events 20+ years ago come back revise their assesment ? it would probably cost them all two or three thousand dollars trip , but course , it would stop thousand if not million dollars sales these recollections which wish fullfilling fantasies begin . all el salvador suffered during this time , why perpetuate suffering ? what any three days any given city north america ? could'nt " glass half empty " scenario drawn horrify any sensible person every wanting visit there , simply selectively clipping daily paper ? i think so . 1
i am ad admirer steve previous books his line columnfor usa today . i also seen him speak person . his insightinto today small business marketplace quite impressive . i think he sums up entrepreneur philosophy his phrase , passion before profit . if you not passion your work , you probably not see profit you desire . i look forward steve next publication 1
coyote waits one hillerman best . i read most hillerman navajo mysteries found this one near top , prose simple elegant , ( no wasted words here ) landscapes descriptive vivid ( but not romantic ) . coyote waits excellent mystery , not overly complex or mind-numbingly predictable . this hillerman top form there few like him . 1
those who skeptical just anything coming llewellyn , i say , if they continue release extremely high caliber material like christopher penczak temple witchcraft series , then they fully redeem themselves publishers . though i share concerns other reviewers lack separation sets exercises cds , after listening several tracks i now believe exercises recorded way specific reason . series meditations visualizations , recorded , afforded me rich experience helped calm my mind increase my focus within first three days receiving set ! example , after initial relaxation counting-down induction , first " set " takes you through 3 ( or four ? ) sets simple visualization exercises . afterwards , he counts you up meditation state full awareness grounds you light chakra sweep clearing affirmation . each segment begins ends same calm , balanced safe manner . when i experienced exercises first time , i appreciated he didn't short-change coming-back-to-awareness sequence end each meditation , like some meditation recordings i've heard . if you're considering companion cds books , i would consider this required item purchase books . keep mind , cds companion books--they're not audio version entire text , just exercises , which comes very handy if you don't want work your meditation trance while balancing book your lap . many , many , many blessings mr. penczak his excellent soothing voice , caring warm reading , top-knotch level work this cd all his books . bright blessings 1
this first dirk pitt many adventures . i read many other dirk pitt books , so it especially nice read first book ! always , it action packed novel . lots good plot twists keep my interest until final page . i highly recommend it very good action adventure 1
this books stands together " black cross " among best greg iles written . plot evolves around secret nazi diary everybody wants lay hands . it long thriller so many characters many subplots , but iles mastery takes you thru different stories lead explosive climax . highly recommended . 1
highly recommend this one wheather or not you into military history . this book addresses social problems , structure everyday problems found our country today , looking through eyes specialized group . this book should added any military collection . author very good job reporting . book easy read quite informative well thought provoking . thank you mr atkison 1
it very rare modern biography truly justice life its subject . all too often , subject material overshadowed vain attempts author sensationalize events individual life without providing much true knowledge subject . however , such sensationalistic biography not undertaken humphrey carpenter , because , we this most excellent resource life times j.r.r. tolkien . perhaps most prominent trait carpenter work insight into effects various events tolkiens life his literary scholarly development . since j.r.r. tolkien defined his catholic faith , his scholarship , his writing , this important consideration biographer . influenced many sources , it only appropriate these considered understanding development tolkien many works throughout his carreer . effects his family , schooling , world war i service , his friendships , his marriage carefully considered explained . furthermore , carpenter often shows precise events which inspired beginning many tolkien languages literary works . it awe-inspiring feel though you there , beside great scholar , he discovers these ideas begins shape them . indeed , anyone interested developments great mind , this biography highly recommended . i believe one who hasn't even read works tolkien would find this most fulfilling . however , those who indeed read tolkien works , this biography nearly necessary read beginning understand how this grand scholar developed 1
thomas paine quot ; rights manquot ; truly classic defense self government reprsentative republicanism . paine copmletely demolishes edmund burke defense aristocracy monarchy outmoded absurd institiutions . paine shows immorality monarchy plunder it commits it own people through high taxes , unjust property laws , priveleges nobility . paine shows virtues representative system over monarchial form . he denounces aristocracy monarchy quot ; fraudsquot ; based upon tyranny . first review murphy critsizing paine sort statist way off mark . paine recommend many ideals welfare state . it must remembered he speaking age where large wealthy aristocracy ruled alongside monarch , living luxury off high taxes drained middle , lower working classes . paine one formost defenders freethought religion , speech , ideas . imply paine sort 18th century fascist utterly absurd ahistorical . paine not enemy property , just enemy aristocracy , who his day not obtain property hard work . usually property rights monarchial nations written favor wealthy powerful , grant them priveleges expense populace . paine completely destroys ideal chosen few meant or ordained god rule . if you love freedom , you can't go wrong quot ; rights manquot ; 1
after reading all unbridled vitriol dawn marie martin-ali , i just order this book ! i just received it , browsed through it , read little , am glad i bought it . $24.00 may bit high paperback , but it over 500 pages long . how many you believe woman incensed book would read anywhere near 500 pages book ? she says she laughed how blind egotistical book . after reading her post , there anyone here who believes this woman ever laughed anything her life ? author , rich zubaty , lot say men women how this country going downhill due its unchecked feminization . he not whining , he ranting ... telling it like it . if you're interested politically correct , this not book you . if you're wondering why it seems like men running things this world but it increasingly feels like women , expense us men , then this book you . i apologize wasting your time bit since i haven't yet read book full , but i just add my two-cents response dawn marie extended scream . what you expect modern woman sporting hyphenated last name ? way , it seems me everything that wrong this world women fault since they comprise 51% population . wherever men charge , it women over men who voted or enabled them there you bet these men charge those who support ( kiss up ) women over men most cases . why ? women more votes ! after all , how else could majority group classified garner special rights ostensibly reserved minorities ? what racket 1
my only caveat this otherwise enjoyable installment eve dallas series web site not prominently state ( i.e. , i missed it ! ) this previously published part anthology . i made mistake only checking publishing date , decided it new novella published independently ( would deserved , given track record series ) , ordered it without checking further . my bad . but reminder readers who want buy everything series -- sure read description carefully enough determine whether it previously-published-in-a-book-you-already-own item ! 1
this first oliver sacks book i've read i found it fascinating informative . once i started case history i hard-put stop reading until i found out end result . i particularly enjoyed stories amnesiac greg colorblind artist . sacks puts human face insights how our brains work intellectually stimulating yet emotionally touching way . i found story virgil , blind man who gets his sight back must learn how see his 50s particularly heart-wrenching . only story i bailed out autistic woman who works cattle slaughterhouse . ( i could not handle graphic nature story . ) i definitely recommend this book if you appreciate shows like nova or if you watch discovery television . anyone who wants know more mysteries our human brains enriched this book 1
three months ago i diagnosed insulin resistance , high blood pressure enlarged/fatty liver . under stress continuously over last decade caring two elderly family memembers numerous health problems - i not taken care myself .. well , after reading applying ' principle ' my own life , i feel tho ' i re-born - age 66 ! i lost 20 pounds without even trying ... my blood pressure now consistently within normal range , my blood work perfect i more energy than i've since i my 30s ! i am not constantly thinking food - satisfied after every meal no longer cravings sweets -it ( they say ) miracle ! i highly recommend this book - testimonies some her patients inspire you - i'm sucess sory - i would hope everyone interested regaining their health control their life , give this sensible , no nonsense way chance - you may very well ( like me ) able correct some your health problems without becoming slave prescription drugs rx ... prescription drugs . my physician his wife registered nurse amazed my progress told me they wish all their patients would able incentive desire take control their life - i admit , i couldn't it my own . i owe it dr. diana schwartzbein ! i highly recommend this book . 1
mr. jean-jacques bares nitty gritty details where how look information value companies , determining which techniques applicable when , arriving valuation range based triangulation multiple relevant frameworks . imho , he spends bit too much time philosophizing -perhaps , this consistent mental framework useful value investors starting out afresh 1
this excellent eye opening book misconceptions non-muslims some muslims islam . author discusses issues such fatwas jihad very well manner claers many false understandings terms . he also " breaks off " some orientalist such bernard lewis samuel huntington pushing these false images islam modern world 1
not what i expecting . very hard read it written back dark ages english used tough -1
2000 rough year publishing history south africa , even one superbly written brilliantly researched leonard thompson far too blandly titled history south africa . so much hung still balance , precarious circumstance so potent it reduced thompson this final , modest sentence : ' nothing preordained human history . 2000 it still conceivable dreams nelson mandela , thabo mbeki , millions other south africans would eventually , some fashion , triumph . indeed . six years later , this reviewer opportunity observe astonishing steps south african people taken towards establishing multiracial civil society . although immense challenges remain , mandela , mbeki , even more sympathetically reviewed de klerk rightly seen protagonists - though hardly equal stature - one modern history great human dramas . leonard thompson proven himself equal task chronicling all south africa known historical periods lucidity well served its subject matter . rarely history go down so easily hungrily thompson 358 lovingly written pages . six years since its publication so full one longs volume thompson angle , hopefully more confident victory remains so undetermined human history - time time most longsuffering places - achieved . thompson celebrating south african people realization secularly sainted elder mandela vision , say , ten years 2006 . now * there * sequel worth pre-ordering . meantime , it would difficult find single volume so blessed historian virtues one thompson given us 1
here argument which merits particular accolade : it one few modern academic theories whose acceptance withstood test time . max weber claim , protestant ethic provided psychological/sociological framework emergence capitalism formative 16th 17th centuries surprisingly outlived , its original whole , such momentous theses einsteinian relativity , extent it remains so far unscathed inevitable skeptical critique , tact its primary tenets . i would go further asserting calvin progenitive endorsement usury ( original sense lending capital interest ) during his rule geneva ( which yet remains hub international banking ) marked not only pivotal moment birth modern capitalism thus , emergence modern problematic , but also , signal phase 180 degree ideological turn christ message its initial , divine articulation . you who seek know what usurps possibility peace earth good everyone , look no further than teaching which judges those whom it knows nothing , prerequisite social interaction , which divides trusting gentle birth , mere children , into saved damned , superior inferior , not , success failure , accepted rejected , which last presumes justification all these brutal criminal acts , putative understanding intricate supernatural wisdom comprehensive universal plan , temerity assign every nature place this plan , extension , place business plan every multi-national corporation , who , through blindness engendered its aegis , sees its leadership crucial strangely ever belated issue bringing " god glory earth " , we know not when or how . short , look no further than `institutes ' institutions calvin , how they open way twisting perverting , condemning sovereign gift christ ( altruistic love ) , less devout though no less benighted souls , narrowest most selfish ends . course , scholar such magnitude weber hardly goes this far impugning what appears cranky crackpot like myself root cause much trouble our world : justification ungoverned capitalist exploitation few `elect ' . but , ostensively , least , his close analyses relevant texts tell . i begin end , justly noted conclusion his his argument : " puritan wanted work calling ; we forced so . when asceticism carried out monastic cells into everyday life , began dominate worldly morality , it its part building tremendous cosmos modern economic order . this order now bound technical economic conditions machine production which to-day determine lives all individuals who born into this mechanism , not only those directly concerned economic acquisition , irresistible force . perhaps it so determine them until last ton fossilized coal burnt . baxter view care external goods should only lie shoulders `saint like light cloak which thrown aside any moment ' . but fate decreed cloak should become iron cage . " ( 123)weber carefully traces transition contemplative detachment medieval christian monasticism mysticism , which least preserved space vision edenic enchantment world ( although he not real clear how this concept meshed austerity christ radical moral demands - more see brilliant work his associate , ernst troeltsch ) , `iron cage ' lockstep , treadmill , sodomic devaluation world early modern european mind . what me one most revealing passages work , weber lays bare predicament which first calvinists , such those , who , escaped iniquitous egypt old world , survived , most often racked disease , starvation , desperation , uncertain crossing red sea , shear force faith beneficence almighty , trod precipitously those fateful steps down plank , their bibles clutched their breasts , touch terra firma new promised land , stand edge eden , pristine , magnificent wilderness , which , handiwork aeons , mere few centuries would crushed , pulverized , buried under billions tonnage concrete garbage , patch-marked every conceivable form human filth corruption inexorable weight commitment this false ideal undoubtedly true but unknown god , utter , bewildering , undeniable terror . " its extreme inhumanity this doctrine must above all one consequence life generation which surrendered its magnificent consistency . feeling unprecedented inner loneliness single individual . what man age reformation most important thing life , his eternal salvation , he forced follow his path alone meet destiny which decreed him eternity . no one could help him . no priest , chosen one understand word god only his own heart . no sacraments , though sacraments ordained god increase his glory , must hence scrupulously observed , they not means attainment grace , but only subjective externa subsidia faith . no church , though it held externa ecclesiam nulla salus sense whosoever kept away true church could never belong god chosen band , nevertheless membership external church included doomed . they should belong it subjected its discipline , not order thus attain salvation , impossible , but because , glory god , they too must forced obey his commandments . finally , even no god . even christ died only elect , whose benefit god decreed his martyrdom eternity . ( calvin openly stated this assertion sermon given broek 1609 centrally implies it throughout his teaching ) thus , complete elimination salvation through church sacraments ( which lutheranism no means developed its final conclusions ) , what formed absolutely decisive difference catholicism . great historic process development religions , elimination magic world which begun old hebrew prophets , conjunction hellenistic scientific thought , repudiated all magical means salvation superstition sin , came here its logical conclusion . " ( 60-61)to prove salvation , earthly success , became impetus disciplines which propelled emergent capitalism dominant social form western civilization . all our social forms must ethical basis justification - live rationally adhere moral code . this code calvinism provided , eschewing impulse universal love we find espoused later chapters john , where new law , new dispensation unequivocal unprecedented call altruism , favor redeeming , once again , strategy `divide conquer ' mightily prized caesar legions who would follow him . again , weber : " but course its development calvinism added something positive this , idea necessity proving one faith worldly activity . therein it gave broader groups religiously inclined people positive incentive asceticism . founding its ethic doctrine predestination , it substituted spiritual aristocracy monks outside above world spiritual aristocracy predestined saints god within world . it aristocracy which , its character indelebilis , divided eternally damned remainder humanity more impassable its invisibility more terrifying gulf , than separated monk middle ages rest world him , gulf which penetrated all social relations its sharp brutality . this consciousness divine grace elect holy accompanied attitude toward sin one neighbor , not sympathetic understanding based consciousness one own weakness , but hatred contempt him enemy god bearing signs eternal damnation . " ( 74-75)for those you who read reviews help term papers such , i given you what i esteem essential passages - but , this book one which categorically must read , regardless work required - your health , your understanding world today , your orientation , your survival . not regard this reading optional . 1
i consider myself completely unqualified quot ; reviewquot ; poetry , but i must say i find gunn work wholly satisfying moving . i read poetry rarely -- dabbling self-indulgently bit anne sexton when i'm feeling blue morbid -- but i purchased quot ; man nightsweatsquot ; it paperback release kept it near hand since . when quot ; boss cupidquot ; published , friend presented me book i devoured it . it nearly two months now , not day gone i haven't revisited book , either physically reading or musing its charms . long live thom gunn 1
choices always tough , michele bolton third shift makes them so much easier make . i am professional woman who , like many other readers this book , am mother , wife involved community member well . societal infrastructure women hasn't yet caught up our aspirations women -- best work , best home , change world -- it because we live this transitional era bolton book so important women like me read . instead chastizing ourselves trying take so much , bolton study shows questioning oneself others very essence successful woman . addition providing useful suggestions professional women corporate workplace ( feel ) more successful , bolton also turns her attention entrepreneurial women launching their own businesses , move she says so much more than job change , but involves more profound change one very identity . finally , bolton even offers several chapters suggestions quot ; stay-at-homequot ; moms , so no matter what your life choices , you find out how feel better them reading this book ! best all this book personal voice author . she writes researcher , academic executive coach , but also woman mother . you read each chapter ( even ones don't seem relate you directly ) , you often feel though you reading yourself or someone you know . take time buy this book then sit down browse through it . this book won't change world , but it change how you look world , how you feel your place it 1
i concur most praise other reviewers , though someone who willingly chose megashul i am probably bit less dissatisfied ordinary synagogues than they . caveat or two : ( 1 ) schwarz seems writing distinctly quot ; new ageyquot ; audience -- baby boomers , politically ultraliberal , oriented towards mysticism rather than learning . i suspect many unaffilated jews aren't type would-be congregant schwarz most interested . ( 2 ) i don't think schwarz emphasizes education much i would ; certainly , i chose my shul partially because it seemed more educational opportunities than smaller ones ( e.g. study session after services saturday ) 1
what this thing ?!?!? - john hersey says introduction ( page xxviii ) , quot ; there never , there never , anything quite like this book . quot ; -on back cover , dashing agee pictured glass what one presumes shot strong stuff his hand . appropriately , because writing resembles nothing so much ( times ) divinely inspired inebriety . he bounces one form writing next ( poetry , descriptive prose , vituperative essay ) without so much feint segue . there really no narrative form speak . it seems clear ( me least ) agee didn't know himself what he doing times , striking pictures evans never seem connect way they should agee prose . it rather like characters james dickey deliverence stumbled out into swath impoverished farmland write book take some pictures rather than into soon-to-be dammed up river take ill-advised canoe trip . ( one not surprised , somehow , learn agee one dickey great literary heroes . ) .... yet , all muddle , or perhaps because it , book disconcerting charm not let one . i don't know where pinpoint it or how analyze it . but it there , like some mischievous elf standing before your eyes who not leave no matter how many times you open shut your eyes shake your head ... there paragraph quot ; porchquot ; section toward end book , describing girl dawning her sexuality : quot ; phase so unassailably beyond any meaning tenderness trust , so like opening first living upon shining young earth its first morning ... quot ; book finest moments , agee best sections writing , we feel this painfully fleeting innocence bliss wafting over lives simple hard-bitten tenant farmers , presence almost physical amidst cruel hardships they endure . perhaps this part book mysterious hold generations readers 1
get this set if you plan bad time . barely you ' good evening ' when lessons quickly turn " stop thief ! " or " he stole my watch " or better yet , " i want attorney " -- all which phrases i never used france . fodor should good sense give practical lessons first , etiquette , directions , service , culture etc . before launching into rude commands pick-pocket paranoia -1
peter mayle breakthrough book remains classic mediterranean travel narrative . elegant witty writer , mayle set standard travel writers 1990s , he difficult equal present day . reading re-reading " year provence " like coming home again again faithful friend . mayle absolutely superb ! next best thing actual travel . 1
complete , helpful , easy find information you looking . if you only own one book how publish children book , make it this one . you can't go wrong 1
read several different translations lysistrata , i report one you select may make all difference your opinion this early comedy . roche translation very vulgar but good footnotes : get ready cockney spartans , however . jack lindsay translation , 1925 ( included bantam edition aristophanes ) seems overly literary comparison original but lacks notes . it reads well , though sounds little old-fashioned . bawdry present but made less direct ; this one spartan dialect scottish . i found parker translation least satisfactory . " hillbilly " dialect he gives spartans painfully overdone , not mention inaccurate , speeches awkward pedestrian . excellent edition overall alan . sommerstein penguin classic " aristophanes : lysistrata other plays . " introduction notes extremely info
gitextract_rsk_fl8v/
├── README.md
├── induction_network/
│ ├── config.json
│ ├── data_helper.py
│ ├── metrics.py
│ ├── model.py
│ ├── predict.py
│ └── trainer.py
├── prototypical_network/
│ ├── config.json
│ ├── data_helper.py
│ ├── metrics.py
│ ├── model.py
│ └── trainer.py
├── relation_network/
│ ├── config.json
│ ├── data_helper.py
│ ├── metrics.py
│ ├── model.py
│ └── trainer.py
├── reviews/
│ ├── english
│ ├── eval/
│ │ ├── books.t2
│ │ ├── books.t4
│ │ ├── books.t5
│ │ ├── dvd.t2
│ │ ├── dvd.t4
│ │ ├── dvd.t5
│ │ ├── electronics.t2
│ │ ├── electronics.t4
│ │ ├── electronics.t5
│ │ ├── kitchen_housewares.t2
│ │ ├── kitchen_housewares.t4
│ │ └── kitchen_housewares.t5
│ └── train/
│ ├── apparel.t2
│ ├── apparel.t4
│ ├── apparel.t5
│ ├── automotive.t2
│ ├── automotive.t4
│ ├── automotive.t5
│ ├── baby.t2
│ ├── baby.t4
│ ├── baby.t5
│ ├── beauty.t2
│ ├── beauty.t4
│ ├── beauty.t5
│ ├── camera_photo.t2
│ ├── camera_photo.t4
│ ├── camera_photo.t5
│ ├── cell_phones_service.t2
│ ├── cell_phones_service.t4
│ ├── cell_phones_service.t5
│ ├── computer_video_games.t2
│ ├── computer_video_games.t4
│ ├── computer_video_games.t5
│ ├── gourmet_food.t2
│ ├── gourmet_food.t4
│ ├── gourmet_food.t5
│ ├── grocery.t2
│ ├── grocery.t4
│ ├── grocery.t5
│ ├── health_personal_care.t2
│ ├── health_personal_care.t4
│ ├── health_personal_care.t5
│ ├── jewelry_watches.t2
│ ├── jewelry_watches.t4
│ ├── jewelry_watches.t5
│ ├── magazines.t2
│ ├── magazines.t4
│ ├── magazines.t5
│ ├── music.t2
│ ├── music.t4
│ ├── music.t5
│ ├── office_products.t4
│ ├── office_products.t5
│ ├── outdoor_living.t2
│ ├── outdoor_living.t4
│ ├── outdoor_living.t5
│ ├── software.t2
│ ├── software.t4
│ ├── software.t5
│ ├── sports_outdoors.t2
│ ├── sports_outdoors.t4
│ ├── sports_outdoors.t5
│ ├── toys_games.t2
│ ├── toys_games.t4
│ ├── toys_games.t5
│ ├── video.t2
│ ├── video.t4
│ └── video.t5
└── siamese_network/
├── config.json
├── data_helper.py
├── metrics.py
├── model.py
└── trainer.py
SYMBOL INDEX (150 symbols across 17 files)
FILE: induction_network/data_helper.py
class InductionData (line 17) | class InductionData(object):
method __init__ (line 18) | def __init__(self, output_path: str, sequence_length: int = 100, num_c...
method load_data (line 62) | def load_data(data_path: str) -> Dict[str, Dict[str, List[List[str]]]]:
method remove_stop_word (line 86) | def remove_stop_word(self, data: Dict[str, Dict[str, List[List[str]]]]...
method get_word_vectors (line 110) | def get_word_vectors(self, vocab: List[str]) -> np.ndarray:
method gen_vocab (line 148) | def gen_vocab(self, words: List[str]) -> Dict[str, int]:
method trans_to_index (line 177) | def trans_to_index(data: Dict[str, Dict[str, List[List[str]]]], word_t...
method choice_support_query (line 191) | def choice_support_query(self, task_data: Dict[str, List[List[int]]])\
method samples (line 229) | def samples(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
method gen_data (line 251) | def gen_data(self, file_path: str) -> Dict[str, Dict[str, List[List[in...
method padding (line 265) | def padding(self, sentences: List[List[int]]) -> List[List[int]]:
method next_batch (line 276) | def next_batch(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
FILE: induction_network/metrics.py
function mean (line 6) | def mean(item: list) -> float:
function accuracy (line 16) | def accuracy(pred_y, true_y):
function binary_precision (line 33) | def binary_precision(pred_y, true_y, positive=1):
function binary_recall (line 53) | def binary_recall(pred_y, true_y, positive=1):
function binary_f_beta (line 73) | def binary_f_beta(pred_y, true_y, beta=1.0, positive=1):
function get_binary_metrics (line 91) | def get_binary_metrics(pred_y, true_y, f_beta=1.0):
function multi_precision (line 106) | def multi_precision(pred_y, true_y, labels):
function multi_recall (line 122) | def multi_recall(pred_y, true_y, labels):
function multi_f_beta (line 138) | def multi_f_beta(pred_y, true_y, labels, beta=1.0):
function get_multi_metrics (line 155) | def get_multi_metrics(pred_y, true_y, labels, f_beta=1.0):
FILE: induction_network/model.py
class InductionModel (line 8) | class InductionModel(object):
method __init__ (line 9) | def __init__(self, config, vocab_size, word_vectors):
method model_structure (line 31) | def model_structure(self):
method dynamic_routing (line 118) | def dynamic_routing(self, support_encoding, iter_routing=3):
method neural_tensor_layer (line 161) | def neural_tensor_layer(self, class_vector, query_encoder):
method _attention (line 207) | def _attention(self, H, scope_name):
method get_optimizer (line 235) | def get_optimizer(self):
method init_saver (line 249) | def init_saver(self):
method train (line 256) | def train(self, sess, batch, dropout_prob):
method eval (line 274) | def eval(self, sess, batch):
method infer (line 289) | def infer(self, sess, batch):
FILE: induction_network/predict.py
function online_predict (line 21) | def online_predict():
FILE: induction_network/trainer.py
class InductionTrainer (line 11) | class InductionTrainer(object):
method __init__ (line 12) | def __init__(self, args):
method load_data (line 27) | def load_data(self, is_training=True):
method create_model (line 45) | def create_model(self):
method train (line 54) | def train(self):
FILE: prototypical_network/data_helper.py
class PrototypicalData (line 17) | class PrototypicalData(object):
method __init__ (line 18) | def __init__(self, output_path: str, sequence_length: int = 100, num_c...
method load_data (line 62) | def load_data(data_path: str) -> Dict[str, Dict[str, List[List[str]]]]:
method remove_stop_word (line 86) | def remove_stop_word(self, data: Dict[str, Dict[str, List[List[str]]]]...
method get_word_vectors (line 110) | def get_word_vectors(self, vocab: List[str]) -> np.ndarray:
method gen_vocab (line 148) | def gen_vocab(self, words: List[str]) -> Dict[str, int]:
method trans_to_index (line 177) | def trans_to_index(data: Dict[str, Dict[str, List[List[str]]]], word_t...
method choice_support_query (line 191) | def choice_support_query(self, task_data: Dict[str, List[List[int]]])\
method samples (line 229) | def samples(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
method gen_data (line 251) | def gen_data(self, file_path: str) -> Dict[str, Dict[str, List[List[in...
method padding (line 265) | def padding(self, sentences: List[List[int]]) -> List[List[int]]:
method next_batch (line 276) | def next_batch(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
FILE: prototypical_network/metrics.py
function mean (line 6) | def mean(item: list) -> float:
function accuracy (line 16) | def accuracy(pred_y, true_y):
function binary_precision (line 33) | def binary_precision(pred_y, true_y, positive=1):
function binary_recall (line 53) | def binary_recall(pred_y, true_y, positive=1):
function binary_f_beta (line 73) | def binary_f_beta(pred_y, true_y, beta=1.0, positive=1):
function get_binary_metrics (line 91) | def get_binary_metrics(pred_y, true_y, f_beta=1.0):
function multi_precision (line 106) | def multi_precision(pred_y, true_y, labels):
function multi_recall (line 122) | def multi_recall(pred_y, true_y, labels):
function multi_f_beta (line 138) | def multi_f_beta(pred_y, true_y, labels, beta=1.0):
function get_multi_metrics (line 155) | def get_multi_metrics(pred_y, true_y, labels, f_beta=1.0):
FILE: prototypical_network/model.py
class PrototypicalModel (line 8) | class PrototypicalModel(object):
method __init__ (line 9) | def __init__(self, config, vocab_size, word_vectors):
method model_structure (line 29) | def model_structure(self):
method _attention (line 128) | def _attention(self, H, scope_name):
method get_optimizer (line 158) | def get_optimizer(self):
method init_saver (line 172) | def init_saver(self):
method train (line 179) | def train(self, sess, batch, dropout_prob):
method eval (line 196) | def eval(self, sess, batch):
method infer (line 211) | def infer(self, sess, batch):
FILE: prototypical_network/trainer.py
class PrototypicalTrainer (line 11) | class PrototypicalTrainer(object):
method __init__ (line 12) | def __init__(self, args):
method load_data (line 28) | def load_data(self, is_training=True):
method create_model (line 46) | def create_model(self):
method train (line 55) | def train(self):
FILE: relation_network/data_helper.py
class RelationData (line 17) | class RelationData(object):
method __init__ (line 18) | def __init__(self, output_path: str, sequence_length: int = 100, num_c...
method load_data (line 62) | def load_data(data_path: str) -> Dict[str, Dict[str, List[List[str]]]]:
method remove_stop_word (line 86) | def remove_stop_word(self, data: Dict[str, Dict[str, List[List[str]]]]...
method get_word_vectors (line 110) | def get_word_vectors(self, vocab: List[str]) -> np.ndarray:
method gen_vocab (line 148) | def gen_vocab(self, words: List[str]) -> Dict[str, int]:
method trans_to_index (line 177) | def trans_to_index(data: Dict[str, Dict[str, List[List[str]]]], word_t...
method choice_support_query (line 191) | def choice_support_query(self, task_data: Dict[str, List[List[int]]])\
method samples (line 229) | def samples(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
method gen_data (line 251) | def gen_data(self, file_path: str) -> Dict[str, Dict[str, List[List[in...
method padding (line 265) | def padding(self, sentences: List[List[int]]) -> List[List[int]]:
method next_batch (line 276) | def next_batch(self, data_ids: Dict[str, Dict[str, List[List[int]]]]) \
FILE: relation_network/metrics.py
function mean (line 6) | def mean(item: list) -> float:
function accuracy (line 16) | def accuracy(pred_y, true_y):
function binary_precision (line 33) | def binary_precision(pred_y, true_y, positive=1):
function binary_recall (line 53) | def binary_recall(pred_y, true_y, positive=1):
function binary_f_beta (line 73) | def binary_f_beta(pred_y, true_y, beta=1.0, positive=1):
function get_binary_metrics (line 91) | def get_binary_metrics(pred_y, true_y, f_beta=1.0):
function multi_precision (line 106) | def multi_precision(pred_y, true_y, labels):
function multi_recall (line 122) | def multi_recall(pred_y, true_y, labels):
function multi_f_beta (line 138) | def multi_f_beta(pred_y, true_y, labels, beta=1.0):
function get_multi_metrics (line 155) | def get_multi_metrics(pred_y, true_y, labels, f_beta=1.0):
FILE: relation_network/model.py
class RelationModel (line 8) | class RelationModel(object):
method __init__ (line 9) | def __init__(self, config, vocab_size, word_vectors):
method model_structure (line 29) | def model_structure(self):
method neural_tensor_layer (line 111) | def neural_tensor_layer(self, class_vector, query_encoder):
method _attention (line 157) | def _attention(self, H, scope_name):
method get_optimizer (line 187) | def get_optimizer(self):
method init_saver (line 201) | def init_saver(self):
method train (line 208) | def train(self, sess, batch, dropout_prob):
method eval (line 226) | def eval(self, sess, batch):
method infer (line 241) | def infer(self, sess, batch):
FILE: relation_network/trainer.py
class RelationTrainer (line 11) | class RelationTrainer(object):
method __init__ (line 12) | def __init__(self, args):
method load_data (line 28) | def load_data(self, is_training=True):
method create_model (line 46) | def create_model(self):
method train (line 55) | def train(self):
FILE: siamese_network/data_helper.py
class SiameseData (line 17) | class SiameseData(object):
method __init__ (line 18) | def __init__(self, output_path: str, sequence_length: int = 200, neg_s...
method load_data (line 52) | def load_data(file_path: str) -> Dict[str, List[List[str]]]:
method remove_stop_word (line 79) | def remove_stop_word(self, data: Dict[str, List[List[str]]]) -> List[s...
method get_word_vectors (line 100) | def get_word_vectors(self, vocab: List[str]) -> np.ndarray:
method gen_vocab (line 122) | def gen_vocab(self, words: List[str]) -> Dict[str, int]:
method trans_to_index (line 151) | def trans_to_index(data: Dict[str, List[List[str]]], word_to_index: Di...
method train_samples (line 162) | def train_samples(self, data_ids: Dict[str, List[List[int]]]) -> List[...
method eval_sample (line 184) | def eval_sample(data_ids: Dict[str, List[List[int]]]) \
method gen_data (line 205) | def gen_data(self, file_path: str) -> Union[List[Tuple[List[int], List...
method padding (line 222) | def padding(self, first_sentences: List[List[int]], second_sentences: ...
method next_batch (line 239) | def next_batch(self, data: List[Tuple[List[int], List[int], int]], bat...
FILE: siamese_network/metrics.py
function mean (line 6) | def mean(item: list) -> float:
function accuracy (line 16) | def accuracy(pred_y, true_y):
function binary_precision (line 33) | def binary_precision(pred_y, true_y, positive=1):
function binary_recall (line 53) | def binary_recall(pred_y, true_y, positive=1):
function binary_f_beta (line 73) | def binary_f_beta(pred_y, true_y, beta=1.0, positive=1):
function get_binary_metrics (line 91) | def get_binary_metrics(pred_y, true_y, f_beta=1.0):
function multi_precision (line 106) | def multi_precision(pred_y, true_y, labels):
function multi_recall (line 122) | def multi_recall(pred_y, true_y, labels):
function multi_f_beta (line 138) | def multi_f_beta(pred_y, true_y, labels, beta=1.0):
function get_multi_metrics (line 155) | def get_multi_metrics(pred_y, true_y, labels, f_beta=1.0):
FILE: siamese_network/model.py
class SiameseModel (line 8) | class SiameseModel(object):
method __init__ (line 9) | def __init__(self, config, vocab_size, word_vectors):
method model_structure (line 26) | def model_structure(self):
method get_optimizer (line 140) | def get_optimizer(self):
method init_saver (line 154) | def init_saver(self):
method train (line 161) | def train(self, sess, batch, dropout_prob):
method eval (line 179) | def eval(self, sess, batch):
method infer (line 194) | def infer(self, sess, batch):
FILE: siamese_network/trainer.py
class SiameseTrainer (line 14) | class SiameseTrainer(object):
method __init__ (line 15) | def __init__(self, args):
method load_data (line 31) | def load_data(self, is_training=True):
method create_model (line 40) | def create_model(self):
method padding (line 49) | def padding(self, first_sentences, second_sentences):
method get_prediction (line 66) | def get_prediction(sims):
method eval_model (line 77) | def eval_model(self, sess):
method train (line 104) | def train(self):
Copy disabled (too large)
Download .json
Condensed preview — 91 files, each showing path, character count, and a content snippet. Download the .json file for the full structured content (75,018K chars).
[
{
"path": "README.md",
"chars": 1435,
"preview": "### few-shot learning\n##### Each folder contains an implementation of each model.\n* data_helper. data processing\n* model"
},
{
"path": "induction_network/config.json",
"chars": 755,
"preview": "{\n \"model_name\": \"induction\",\n \"epochs\": 30,\n \"checkpoint_every\": 500,\n \"eval_every\": 500,\n \"learning_rate\": 1e-3,\n"
},
{
"path": "induction_network/data_helper.py",
"chars": 11415,
"preview": "\"\"\"\ndata process\n\"\"\"\n\nimport os\nimport json\nimport random\nimport copy\nfrom collections import Counter\nfrom itertools imp"
},
{
"path": "induction_network/metrics.py",
"chars": 4470,
"preview": "\"\"\"\nperformance metrics function\n\"\"\"\n\n\ndef mean(item: list) -> float:\n \"\"\"\n Calculate the mean of the list\n :pa"
},
{
"path": "induction_network/model.py",
"chars": 14131,
"preview": "\"\"\"\nprototypical network model for few shot learning\n\"\"\"\n\nimport tensorflow as tf\n\n\nclass InductionModel(object):\n de"
},
{
"path": "induction_network/predict.py",
"chars": 3237,
"preview": "#!/usr/bin/env python\n# -*- coding:utf-8 -*-\n\"\"\"\n-------------------------------------------------\n File Name : pr"
},
{
"path": "induction_network/trainer.py",
"chars": 6778,
"preview": "import argparse\nimport json\nimport os\n\nimport tensorflow as tf\nfrom data_helper import InductionData\nfrom metrics import"
},
{
"path": "prototypical_network/config.json",
"chars": 746,
"preview": "{\n \"model_name\": \"prototypical\",\n \"epochs\": 30,\n \"checkpoint_every\": 500,\n \"eval_every\": 500,\n \"learning_rate\": 1e-"
},
{
"path": "prototypical_network/data_helper.py",
"chars": 11417,
"preview": "\"\"\"\ndata process\n\"\"\"\n\nimport os\nimport json\nimport random\nimport copy\nfrom collections import Counter\nfrom itertools imp"
},
{
"path": "prototypical_network/metrics.py",
"chars": 4470,
"preview": "\"\"\"\nperformance metrics function\n\"\"\"\n\n\ndef mean(item: list) -> float:\n \"\"\"\n Calculate the mean of the list\n :pa"
},
{
"path": "prototypical_network/model.py",
"chars": 10776,
"preview": "\"\"\"\nprototypical network model for few shot learning\n\"\"\"\n\nimport tensorflow as tf\n\n\nclass PrototypicalModel(object):\n "
},
{
"path": "prototypical_network/trainer.py",
"chars": 6835,
"preview": "import json\nimport os\nimport argparse\n\nimport tensorflow as tf\nfrom data_helper import PrototypicalData\nfrom model impor"
},
{
"path": "relation_network/config.json",
"chars": 750,
"preview": "{\n \"model_name\": \"relation\",\n \"epochs\": 30,\n \"checkpoint_every\": 500,\n \"eval_every\": 500,\n \"learning_rate\": 1e-3,\n "
},
{
"path": "relation_network/data_helper.py",
"chars": 11413,
"preview": "\"\"\"\ndata process\n\"\"\"\n\nimport os\nimport json\nimport random\nimport copy\nfrom collections import Counter\nfrom itertools imp"
},
{
"path": "relation_network/metrics.py",
"chars": 4470,
"preview": "\"\"\"\nperformance metrics function\n\"\"\"\n\n\ndef mean(item: list) -> float:\n \"\"\"\n Calculate the mean of the list\n :pa"
},
{
"path": "relation_network/model.py",
"chars": 11719,
"preview": "\"\"\"\nprototypical network model for few shot learning\n\"\"\"\n\nimport tensorflow as tf\n\n\nclass RelationModel(object):\n def"
},
{
"path": "relation_network/trainer.py",
"chars": 6769,
"preview": "import json\nimport os\nimport argparse\n\nimport tensorflow as tf\nfrom data_helper import RelationData\nfrom model import Re"
},
{
"path": "reviews/english",
"chars": 623,
"preview": "i\nme\nmy\nmyself\nwe\nour\nours\nourselves\nyou\nyour\nyours\nyourself\nyourselves\nhe\nhim\nhis\nhimself\nshe\nher\nhers\nherself\nit\nits\ni"
},
{
"path": "reviews/eval/books.t2",
"chars": 1166084,
"preview": "casual book browsers who stumble across braden book , \" isaiah effect , \" might undoubtedly drawn implications title : t"
},
{
"path": "reviews/eval/books.t4",
"chars": 1253372,
"preview": "left dead her kidnappers , lore found mysterious woman spanner , who teaches her survive her wits live dark world crime "
},
{
"path": "reviews/eval/books.t5",
"chars": 1233063,
"preview": "before getting this book , i knew advantages shooting raw file format , but dreaded workflow issues associated . bruce b"
},
{
"path": "reviews/eval/dvd.t2",
"chars": 1273681,
"preview": "\" con express \" lots action it , which great because this hides poor writing uninteresting characters . unfortunately , "
},
{
"path": "reviews/eval/dvd.t4",
"chars": 1386797,
"preview": "my son over 2 before we introduced videos . there definitely those which cater younger baby lots random images , but thi"
},
{
"path": "reviews/eval/dvd.t5",
"chars": 1313511,
"preview": "this movie scream ! i laughed until i thought i going die . comedy doesn't get any better than this . characters incredi"
},
{
"path": "reviews/eval/electronics.t2",
"chars": 729622,
"preview": "no free lunch you get what you pay ... verdict this product ? well , poor rating given those who purchased this product "
},
{
"path": "reviews/eval/electronics.t4",
"chars": 691838,
"preview": "works well , especially anyone who still their old console systems use . i my nes snes , both which huge ac adapters , p"
},
{
"path": "reviews/eval/electronics.t5",
"chars": 668317,
"preview": "i received my kingston 256mb sd card just advertised . unit came mail exactly 2 days after iordered . worked perfectly i"
},
{
"path": "reviews/eval/kitchen_housewares.t2",
"chars": 502207,
"preview": "i bought 3 these monitor my invalid mom they don't work well . manual not thorough , but it tell you after you bought pr"
},
{
"path": "reviews/eval/kitchen_housewares.t4",
"chars": 509556,
"preview": "i 3 1/2 year old boxer barks , cries , whines , howls when i go work ... all day ... i know , i recorded it . i went pet"
},
{
"path": "reviews/eval/kitchen_housewares.t5",
"chars": 518187,
"preview": "i picked up dozen home depot less than $5 . same concept , just lot cheaper ! two them holding huge heavy shelf my kitch"
},
{
"path": "reviews/train/apparel.t2",
"chars": 770236,
"preview": "pants i ordered my size very small . they weren't true size all . i would not recommend this item anyone\t-1\nit advertise"
},
{
"path": "reviews/train/apparel.t4",
"chars": 777461,
"preview": "perhaps it my own fault not reading more closely , or failing question somewhat ambiguous product description . fact , i"
},
{
"path": "reviews/train/apparel.t5",
"chars": 771704,
"preview": "i say i disappointed when i opened up package containing my ipod wallet . it cute , but not $60ish cute . first all , it"
},
{
"path": "reviews/train/automotive.t2",
"chars": 85736,
"preview": "lasts only 2 weeks ! try them if you don't believe me\t-1\nwaste money , lasted only 2 weeks this summer . garbage . pay l"
},
{
"path": "reviews/train/automotive.t4",
"chars": 84660,
"preview": "i bought two pair different sizes one pair great but other pair deteriorated edges left water lines first use one lock d"
},
{
"path": "reviews/train/automotive.t5",
"chars": 77266,
"preview": "i bought 3 sets these blades my cars . they lasted 2 weeks ( most ) average summer . bosch or anco blades usually work 2"
},
{
"path": "reviews/train/baby.t2",
"chars": 616461,
"preview": "order cordless monitor any privacy , you need it digital use digital-spread-spectrum ( dss ) technology . 900 mhz best f"
},
{
"path": "reviews/train/baby.t4",
"chars": 616330,
"preview": "i've contacted manufacturer ... alternative way hook crib . they less than helpful . i am thinking returning entire set "
},
{
"path": "reviews/train/baby.t5",
"chars": 637501,
"preview": "i registered entire locomotion collection before my son born very happy it . i love theme , but mobile big disappointmen"
},
{
"path": "reviews/train/beauty.t2",
"chars": 399072,
"preview": "i bought this because friend it it smelled wonderfully roses . there must quality control problem . my bottle no noticib"
},
{
"path": "reviews/train/beauty.t4",
"chars": 369182,
"preview": "i like jonathan anton some his products , but this one very bad one . it smelled like swamp water . his other products s"
},
{
"path": "reviews/train/beauty.t5",
"chars": 392573,
"preview": "i bought this because i fine hair needs washed every day i get tired washing it . i thought i could use this every other"
},
{
"path": "reviews/train/camera_photo.t2",
"chars": 1359825,
"preview": "im not usa . my brother bought me camara trip three months ago it not working !! it serious conection problems body i ca"
},
{
"path": "reviews/train/camera_photo.t4",
"chars": 1397614,
"preview": "bought these my nikon d200 3 months ago . never used tiffen before i took chance recommendation . vignetting issue polar"
},
{
"path": "reviews/train/camera_photo.t5",
"chars": 1329747,
"preview": "well course i read previous reviews regarding amazon shipping grey-market version this timer figured certainly now they "
},
{
"path": "reviews/train/cell_phones_service.t2",
"chars": 155130,
"preview": "beware ! \" product features \" this product specifieda \" call answer end button headset . \" device i received not feature"
},
{
"path": "reviews/train/cell_phones_service.t4",
"chars": 152341,
"preview": "i bought this $30 best buy . what waste money ! ear gels comfortable first , but after hour or so , your ear starts real"
},
{
"path": "reviews/train/cell_phones_service.t5",
"chars": 153665,
"preview": "darn thing broke almost immediately . when i tried switch gel covers ( it comes 3 different sizes ) entire earpiece came"
},
{
"path": "reviews/train/computer_video_games.t2",
"chars": 799902,
"preview": "i bought this mic december after only two nights singing , it completely died ! what complete disappointment . save your"
},
{
"path": "reviews/train/computer_video_games.t4",
"chars": 745430,
"preview": "i bought kr party bundle my boyfriend daughter her birthday . she loves game , but it only two weeks mic dead . it start"
},
{
"path": "reviews/train/computer_video_games.t5",
"chars": 823238,
"preview": "first off , i cannot believe how mad this game made me . i like all kinds games , but honestly trying figure out some le"
},
{
"path": "reviews/train/gourmet_food.t2",
"chars": 189402,
"preview": "vegan , i tried just every tofu product market , nothing ever came close terrible texture these noodles . smell when you"
},
{
"path": "reviews/train/gourmet_food.t4",
"chars": 189983,
"preview": "after reading number positive reviews product , i wanted try it . i am glad i just went my local whole foods supermarket"
},
{
"path": "reviews/train/gourmet_food.t5",
"chars": 179067,
"preview": "i expected something softer texture , but these like chewing rubber flavor . much too hard my 3 y/old child . if you're "
},
{
"path": "reviews/train/grocery.t2",
"chars": 260282,
"preview": "sickly weak queasy stomach after eating bar 4 hours or more . i havent felt so yuky sickly long time . you cannot return"
},
{
"path": "reviews/train/grocery.t4",
"chars": 262965,
"preview": "silly me ! i assumed these bars would taste like spirulina cashews , but only ingredient you taste them , or any their o"
},
{
"path": "reviews/train/grocery.t5",
"chars": 258003,
"preview": "this product so disappointing i discarded entire box after trying one bar . there much better raw food bars market terms"
},
{
"path": "reviews/train/health_personal_care.t2",
"chars": 882331,
"preview": "when i got this pedometer , i found instructions weren't clear . i never get thing work . i pedometers before they alway"
},
{
"path": "reviews/train/health_personal_care.t4",
"chars": 860869,
"preview": "meditation same thing . buy tape or take class\t-1\ni offered one these while cycling thought it very tasty . so good , fa"
},
{
"path": "reviews/train/health_personal_care.t5",
"chars": 882001,
"preview": "expensive ... after three months daily use i can't say it helped my blood pressure . i record my blood pressure every mo"
},
{
"path": "reviews/train/jewelry_watches.t2",
"chars": 192032,
"preview": "my 5-year-old daughter thrilled her locket . it really beautiful . we both quite disappointed , however , when locket it"
},
{
"path": "reviews/train/jewelry_watches.t4",
"chars": 162805,
"preview": "these earrings very pretty , but post way too thick . they killed my ears i return them . i would guess post least 2.5 t"
},
{
"path": "reviews/train/jewelry_watches.t5",
"chars": 189950,
"preview": "these earrings very uncomfortable . i'm not sure if it actually size post so much shape angle -- more like angled bar th"
},
{
"path": "reviews/train/magazines.t2",
"chars": 769841,
"preview": "oh those days , when i college , reading my first issues then subscribing . there great things found its pages , columns"
},
{
"path": "reviews/train/magazines.t4",
"chars": 757645,
"preview": "even if you're \" conservative , \" you gotta admit this one worst magazines around . if you like good writing , don't eve"
},
{
"path": "reviews/train/magazines.t5",
"chars": 804962,
"preview": "this not health magazine you'd expect martha stewart -- it extremely heavy advertisements ( 45% my rough count ) , reall"
},
{
"path": "reviews/train/music.t2",
"chars": 5419675,
"preview": "\" maiden voyage \" appears innumerable lists jazz masterpieces , it clear first listen both composition playing level tec"
},
{
"path": "reviews/train/music.t4",
"chars": 5503501,
"preview": "it beyond me record label would put this out . it so embarassing how bad he rips bright eyes song structure , subject pr"
},
{
"path": "reviews/train/music.t5",
"chars": 5457954,
"preview": "this not what i expected such gifted artist jaheim , he change producers ? music man voice didn't go together well me . "
},
{
"path": "reviews/train/office_products.t4",
"chars": 55901,
"preview": "i bought small one these blank , unlined pages pocket sketchbook . pocket sketchbooks commonly sold art supply stores on"
},
{
"path": "reviews/train/office_products.t5",
"chars": 61835,
"preview": "i bought small one these blank , unlined pages pocket sketchbook . pocket sketchbooks commonly sold art supply stores on"
},
{
"path": "reviews/train/outdoor_living.t2",
"chars": 200032,
"preview": "this seems like great idea - food held basket , so you don't shove skewer through meat . however , little bolts hold dow"
},
{
"path": "reviews/train/outdoor_living.t4",
"chars": 195921,
"preview": "$80 this ? seriously overpriced . if you find something cheaper buy it , this not worth 80 bucks . clamps not capable ho"
},
{
"path": "reviews/train/outdoor_living.t5",
"chars": 192930,
"preview": "hard set up use . no directions can't find anything web . would not buy if i knew this\t-1\ni looking forward purchasing t"
},
{
"path": "reviews/train/software.t2",
"chars": 471376,
"preview": "they hebrew backwards !! you supposed read hebrew right lef t-t he opposite english this cd it left right . i find it ex"
},
{
"path": "reviews/train/software.t4",
"chars": 487888,
"preview": "my boss asked me get this , so he check out latin portion it . what waste ! only latin this cd * latin * american spanis"
},
{
"path": "reviews/train/software.t5",
"chars": 462692,
"preview": "easy language 16 only useful if you're already familiar language you wish learn . i've studying french months before buy"
},
{
"path": "reviews/train/sports_outdoors.t2",
"chars": 804440,
"preview": "... more than couple minutes ( no matter what i ) toilet monster kept falling into drink . overall it quite underwhelmin"
},
{
"path": "reviews/train/sports_outdoors.t4",
"chars": 778731,
"preview": "this stuff very strong smell -- like wd-40 or something . if you stand smell , you might well buy local hardware store -"
},
{
"path": "reviews/train/sports_outdoors.t5",
"chars": 810708,
"preview": "i ordered two these save shipping figured extra tube would good relube year or two . after applying one vial , it seemed"
},
{
"path": "reviews/train/toys_games.t2",
"chars": 1678949,
"preview": "i bought this my 5 year old daughter we tried take very good care it . within few days careful use , one latches bent , "
},
{
"path": "reviews/train/toys_games.t4",
"chars": 1639708,
"preview": "i bought this my 2 yr old daughter . i so surprised quality little tykes . it no storage refridgerator door would not st"
},
{
"path": "reviews/train/toys_games.t5",
"chars": 1653082,
"preview": "this wasn't actually card game . it more book 88 tear out sheets one game each . they no way this played card game . box"
},
{
"path": "reviews/train/video.t2",
"chars": 5852006,
"preview": "this video not live up my expectations . i five-year-old chihuahua who somewhat afraid people lunges bites when stranger"
},
{
"path": "reviews/train/video.t4",
"chars": 5965894,
"preview": "i rented this video sake trip down memory lane . course , fourteen years produce great shift gullibility . i hated this "
},
{
"path": "reviews/train/video.t5",
"chars": 6101288,
"preview": "it not just this film bloated remake quick , clean , near-perfect minimalist thriller . it not much added material ( par"
},
{
"path": "siamese_network/config.json",
"chars": 644,
"preview": "{\n \"model_name\": \"siamese\",\n \"epochs\": 50,\n \"checkpoint_every\": 3000,\n \"eval_every\": 3000,\n \"learning_rate\": 1e-3,\n"
},
{
"path": "siamese_network/data_helper.py",
"chars": 10639,
"preview": "\"\"\"\ndata process\n\"\"\"\n\nimport os\nimport json\nimport random\nimport copy\nfrom collections import Counter\nfrom itertools imp"
},
{
"path": "siamese_network/metrics.py",
"chars": 4470,
"preview": "\"\"\"\nperformance metrics function\n\"\"\"\n\n\ndef mean(item: list) -> float:\n \"\"\"\n Calculate the mean of the list\n :pa"
},
{
"path": "siamese_network/model.py",
"chars": 9645,
"preview": "\"\"\"\n采用text-cnn模型进行多意图分类\n\"\"\"\n\nimport tensorflow as tf\n\n\nclass SiameseModel(object):\n def __init__(self, config, vocab_"
},
{
"path": "siamese_network/trainer.py",
"chars": 7785,
"preview": "import json\nimport os\nimport argparse\n\nimport tensorflow as tf\nimport numpy as np\nfrom data_helper import SiameseData\nfr"
}
]
About this extraction
This page contains the full source code of the jiangxinyang227/few_shot_learning GitHub repository, extracted and formatted as plain text for AI agents and large language models (LLMs). The extraction includes 91 files (71.1 MB), approximately 18.6M tokens, and a symbol index with 150 extracted functions, classes, methods, constants, and types. Use this with OpenClaw, Claude, ChatGPT, Cursor, Windsurf, or any other AI tool that accepts text input. You can copy the full output to your clipboard or download it as a .txt file.
Extracted by GitExtract — free GitHub repo to text converter for AI. Built by Nikandr Surkov.