CS224N Assignment1 Section 1
运行环境需求
# All Import Statements Defined Here
# Note: Do not add to this list.
# All the dependencies you need, can be installed by running .
# ---------------- import sys
assert sys.version_info[0]==3
assert sys.version_info[1] >= 5 from gensim.models import KeyedVectors
from gensim.test.utils import datapath
import pprint
import matplotlib.pyplot as plt
plt.rcParams['figure.figsize'] = [10, 5]
import nltk
nltk.download('reuters')
from nltk.corpus import reuters
import numpy as np
import random
import scipy as sp
from sklearn.decomposition import TruncatedSVD
from sklearn.decomposition import PCA START_TOKEN = '<START>'
END_TOKEN = '<END>' np.random.seed(0)
random.seed(0)
# ----------------
Question 1.1: Implement distinct_words [code] (2 points)
Write a method to work out the distinct words (word types) that occur in the corpus. You can do this with for loops, but it's more efficient to do it with Python list comprehensions. In particular, this may be useful to flatten a list of lists. If you're not familiar with Python list comprehensions in general, here's more information.
You may find it useful to use Python sets to remove duplicate words.
def distinct_words(corpus):
""" Determine a list of distinct words for the corpus.
Params:
corpus (list of list of strings): corpus of documents
Return:
corpus_words (list of strings): list of distinct words across the corpus, sorted (using python 'sorted' function)
num_corpus_words (integer): number of distinct words across the corpus
"""
corpus_words = []
num_corpus_words = -1 # ------------------
# Write your implementation here.
raw_corpus_words = [word for corpu in corpus for word in corpu]
corpus_words = list(set(raw_corpus_words))
corpus_words = sorted(corpus_words)
num_corpus_words = len(corpus_words) # ------------------ return corpus_words, num_corpus_words
Question 1.2: Implement compute_co_occurrence_matrix [code] (3 points)
Write a method that constructs a co-occurrence matrix for a certain window-size
CS224N Assignment1 Section 1的更多相关文章
- keil MDK error: L6236E: No section matches selector - no section 错误
今天板子刚到,新建的第一个工程就报错了. .\Objects\cse.sct(7): error: L6236E: No section matches selector - no section t ...
- 【代码笔记】iOS-一个tableView,两个section
一,效果图. 二,工程图. 三,代码. RootViewController.h #import <UIKit/UIKit.h> @interface RootViewController ...
- gcc/linux内核中likely、unlikely和__attribute__(section(""))属性
查看linux内核源码,你会发现有很多if (likely(""))...及if (unlikely(""))...语句,这些语句其实是编译器的一种优化方式,具 ...
- <section> 标签
最近正在学习html5,刚接触html5,感觉有点不适应,因为有一些标签改变了,特别是div, section article这三个标签,查了一些资料,也试着用html5和css3布局网页,稍微有点头 ...
- [ASP.NET MVC 小牛之路]12 - Section、Partial View 和 Child Action
概括的讲,View中的内容可以分为静态和动态两部分.静态内容一般是html元素,而动态内容指的是在应用程序运行的时候动态创建的内容.给View添加动态内容的方式可归纳为下面几种: Inline cod ...
- $\LaTeX$笔记:Section 编号方式(数字、字母、罗马)&计数器计数形式修改
$\LaTeX$系列根目录: Latex学习笔记-序 IEEE模板中Section的编号是罗马数字,要是改投其他刊物的话可能得用阿拉伯数字,所以可以在导言部分做如下修改(放在导言区宏包调用之后): \ ...
- [DOM Event Learning] Section 4 事件分发和DOM事件流
[DOM Event Learning] Section 4 事件分发和DOM事件流 事件分发机制: event dispatch mechanism. 事件流(event flow)描述了事件对象在 ...
- [DOM Event Learning] Section 3 jQuery事件处理基础 on(), off()和one()方法使用
[DOM Event Learning] Section 3 jQuery事件处理基础 on(),off()和one()方法使用 jQuery提供了简单的方法来向选择器(对应页面上的元素)绑定事件 ...
- [DOM Event Learning] Section 2 概念梳理 什么是事件 DOM Event
[DOM Event Learning] Section 2 概念梳理 什么是事件 DOM Event 事件 事件(Event)是用来通知代码,一些有趣的事情发生了. 每一个Event都会被一个E ...
随机推荐
- PHP获取网址详情页的内容导出到WORD文件
亲自测试效果一般, css的样式文件获取不到 如果没有特殊的样式 或者是内容里面包括样式的 直接输出有样式的内容 然后导出 这样还是可以的 class word { function start ...
- 获取json对象的键数组和值数组
const obj = {a: 1, b: 2, c: 3}; Object.values(obj);//[1, 2, 3] Object.keys(obj);//["a", &q ...
- python爬取 “得到” App 电子书信息
前言 文的文字及图片来源于网络,仅供学习.交流使用,不具有任何商业用途,版权归原作者所有,如有问题请及时联系我们以作处理. 作者: 静觅 崔庆才 PS:如有需要Python学习资料的小伙伴可以加点击下 ...
- Python【day 16-1】面向对象初识
1.面向对象思想 1.面向过程 1.概念 按照事物的发展流程,第一步,第二步,第三步,一步步往下 2.优缺点 1.优点 简单,流水线式的 2.缺点 可扩展性差 2.面向对象 1.概念 对象:是属性和动 ...
- javafx笔记----非javafx线程Platform.runLater赋值不生效情况
Platform.runLater(() -> { // }); Platform.runLater一些情况下没有赋值到fx页面上 采用task方式 Task<SB> task = ...
- dijit/_WidgetBase
英文地址:http://dojotoolkit.org/reference-guide/1.10/dijit/_WidgetBase.html 介绍 dijit/_WidgetBase是Dijit包中 ...
- socket 与 websocket的区别
区别: socket并不是一个协议,而是抽象出来的一层,应用于应用层和传输控制层之间的一组接口, socket是传输控制层协议,websocket是应用层协议 websocket是什么样的协议,具有什 ...
- jQuery中的事件对象(八)
Event 对象代表事件的状态,比如事件在其中发生的元素.键盘按键的状态.鼠标的位置.鼠标按钮的状态. 一.事件对象基本认识 1. 什么时候会产生Event 对象呢? 例如: 当用户单击某个元素的时 ...
- 基于C++的STL的vector实现静态链表,要求包含插入,删除,和查找功能
//main.cpp部分 #include"List.cpp" int main() { StaticList<int> SL; SL.Insert(,); SL.In ...
- [随笔]ICPC2.0
停更半年了.瞎扯下过去,现在与未来. 一.过去 1.插叙 讲道理我应该早就写这段在博客上了,不知怎么一直忘了. 在6月拿到ICPC南昌邀请赛的Ag还是比较满意,满意的最大原因是我弱校从没拿过Ag(? ...