本文整理汇总了Python中utils.ngram_utils._ngrams函数的典型用法代码示例。如果您正苦于以下问题:Python _ngrams函数的具体用法?Python _ngrams怎么用?Python _ngrams使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了_ngrams函数的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: transform_one
def transform_one(self, obs, target, id):
obs_tokens = nlp_utils._tokenize(obs, token_pattern)
target_tokens = nlp_utils._tokenize(target, token_pattern)
obs_ngrams = ngram_utils._ngrams(obs_tokens, self.ngram)
target_ngrams = ngram_utils._ngrams(target_tokens, self.ngram)
pos_list = _inter_norm_pos_list(obs_ngrams, target_ngrams)
return pos_list
开发者ID:amsqr,项目名称:Kaggle_HomeDepot,代码行数:7,代码来源:feature_intersect_position.py
示例2: transform_one
def transform_one(self, obs, target, id):
obs_tokens = nlp_utils._tokenize(obs, token_pattern)
target_tokens = nlp_utils._tokenize(target, token_pattern)
obs_ngrams = ngram_utils._ngrams(obs_tokens, self.ngram)
target_ngrams = ngram_utils._ngrams(target_tokens, self.ngram)
s = 0.
for w1 in obs_ngrams:
for w2 in target_ngrams:
if dist_utils._is_str_match(w1, w2, self.str_match_threshold):
s += 1.
return np_utils._try_divide(s, len(obs_ngrams)*len(target_ngrams))
开发者ID:MrSnark,项目名称:Kaggle_HomeDepot,代码行数:11,代码来源:feature_intersect_count.py
示例3: transform
def transform(self):
# ngrams
obs_ngrams = list(map(lambda x: ngram_utils._ngrams(x.split(" "), self.obs_ngram, "_"), self.obs_corpus))
target_ngrams = list(map(lambda x: ngram_utils._ngrams(x.split(" "), self.target_ngram, "_"), self.target_corpus))
# cooccurrence ngrams
cooc_terms = list(map(lambda lst1,lst2: self._get_cooc_terms(lst1, lst2, "X"), obs_ngrams, target_ngrams))
## tfidf
tfidf = self._init_word_ngram_tfidf(ngram=1)
X = tfidf.fit_transform(cooc_terms)
## svd
svd = TruncatedSVD(n_components=self.svd_dim, n_iter=self.svd_n_iter, random_state=config.RANDOM_SEED)
return svd.fit_transform(X)
开发者ID:amsqr,项目名称:Kaggle_HomeDepot,代码行数:12,代码来源:feature_vector_space.py
示例4: transform_one
def transform_one(self, obs, target, id):
obs_tokens = nlp_utils._tokenize(obs, token_pattern)
target_tokens = nlp_utils._tokenize(target, token_pattern)
obs_ngrams = ngram_utils._ngrams(obs_tokens, self.ngram)
target_ngrams = ngram_utils._ngrams(target_tokens, self.ngram)
val_list = []
for w1 in obs_ngrams:
s = 0.
for w2 in target_ngrams:
if dist_utils._is_str_match(w1, w2, self.str_match_threshold):
s += 1.
val_list.append(np_utils._try_divide(s, len(target_ngrams)))
if len(val_list) == 0:
val_list = [config.MISSING_VALUE_NUMERIC]
return val_list
开发者ID:amsqr,项目名称:Kaggle_HomeDepot,代码行数:15,代码来源:feature_stat_cooc_tfidf.py
示例5: transform_one
def transform_one(self, obs, target, id):
df = self.dfTrain[self.dfTrain["search_term"] == obs].copy()
val_list = [config.MISSING_VALUE_NUMERIC]
if df is not None:
df = df[df["id"] != id].copy()
df = df[df["relevance"] == self.relevance].copy()
if df is not None and df.shape[0] > 0:
target_tokens = nlp_utils._tokenize(target, token_pattern)
target_ngrams = ngram_utils._ngrams(target_tokens, self.ngram)
val_list = []
for x in df[self.target_field]:
x_tokens = nlp_utils._tokenize(x, token_pattern)
x_ngrams = ngram_utils._ngrams(x_tokens, self.ngram)
val_list.append(dist_utils._jaccard_coef(x_ngrams, target_ngrams))
return val_list
开发者ID:MrSnark,项目名称:Kaggle_HomeDepot,代码行数:15,代码来源:feature_group_distance.py
示例6: _get_avg_ngram_doc_len
def _get_avg_ngram_doc_len(self):
lst = []
for target in self.target_corpus:
target_tokens = nlp_utils._tokenize(target, token_pattern)
target_ngrams = ngram_utils._ngrams(target_tokens, self.ngram)
lst.append(len(target_ngrams))
return np.mean(lst)
开发者ID:amsqr,项目名称:Kaggle_HomeDepot,代码行数:7,代码来源:feature_stat_cooc_tfidf.py
示例7: transform_one
def transform_one(self, obs, target, id):
obs_tokens = nlp_utils._tokenize(obs, token_pattern)
target_tokens = nlp_utils._tokenize(target, token_pattern)
obs_ngrams = ngram_utils._ngrams(obs_tokens, self.ngram)
target_ngrams = ngram_utils._ngrams(target_tokens, self.ngram)
val_list = []
for w1 in obs_ngrams:
_val_list = []
for w2 in target_ngrams:
s = dist_utils._edit_dist(w1, w2)
_val_list.append(s)
if len(_val_list) == 0:
_val_list = [ config.MISSING_VALUE_NUMERIC ]
val_list.append( _val_list )
if len(val_list) == 0:
val_list = [ [config.MISSING_VALUE_NUMERIC] ]
return val_list
开发者ID:Anhmike,项目名称:Kaggle_HomeDepot,代码行数:17,代码来源:feature_distance.py
示例8: _get_df_dict
def _get_df_dict(self):
# smoothing
d = defaultdict(lambda : 1)
for target in self.target_corpus:
target_tokens = nlp_utils._tokenize(target, token_pattern)
target_ngrams = ngram_utils._ngrams(target_tokens, self.ngram)
for w in set(target_ngrams):
d[w] += 1
return d
开发者ID:amsqr,项目名称:Kaggle_HomeDepot,代码行数:9,代码来源:feature_stat_cooc_tfidf.py
示例9: _ngram
def _ngram(self, text):
tokens = text.split(" ")
tokens = [token for token in tokens if token not in self.stopwords]
return ngram_utils._ngrams(tokens, self.ngram, " ")
开发者ID:amsqr,项目名称:Kaggle_HomeDepot,代码行数:4,代码来源:data_processor.py
示例10: transform_one
def transform_one(self, obs, target, id):
obs_tokens = nlp_utils._tokenize(obs, token_pattern)
obs_ngrams = ngram_utils._ngrams(obs_tokens, self.ngram)
return np_utils._try_divide(len(set(obs_ngrams)), len(obs_ngrams))
开发者ID:amsqr,项目名称:Kaggle_HomeDepot,代码行数:4,代码来源:feature_basic.py
示例11: transform_one
def transform_one(self, obs, target, id):
obs_tokens = nlp_utils._tokenize(obs, token_pattern)
target_tokens = nlp_utils._tokenize(target, token_pattern)
obs_ngrams = ngram_utils._ngrams(obs_tokens, self.ngram)
target_ngrams = ngram_utils._ngrams(target_tokens, self.ngram)
return np_utils._try_divide(self._get_match_count(obs_ngrams, target_ngrams, self.idx), len(target_ngrams))
开发者ID:amsqr,项目名称:Kaggle_HomeDepot,代码行数:6,代码来源:feature_first_last_ngram.py
注:本文中的utils.ngram_utils._ngrams函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论