当前位置:首页 » 操作系统 » 文本算法

文本算法

发布时间: 2022-01-31 14:21:36

1. 文本自动分类算法有哪些呢

文本自动分类算法主要有朴素贝叶斯分类算法、支持向量机分类算法、KNN算法和决策树算法。
朴素贝叶斯分类算法主要是利用文本中词的特征项和类别的组合概率来估算文本属于哪个类别的概率。
支持向量机分类算分主要是采用特征提取技术把文本信息转换为词向量,然后用词向量与训练好的类别数据进行相似度计算。
KNN算法是在训练集中找到离它最近的k个文本,并根据这些文本的分类来预测待分类文本属于哪一个类别。
决策树算法是首先建立一个基于树的预测模型,根据预测模型来对文本进行预测分类。

2. 深度学习算法哪些适用于文本处理

作者:梅洪源
来源:知乎

现在实践证明,对supervised-learning而言,效果较好的应该算是Recurrent Neural Network (RNN)吧,目前比较火的一类RNN是LSTM -- Long Short Term Memory。
对于这个model而言,最初的发明见于论文--Long Short Term Memory by Hochreiter and Schmidhuber,而之后较好的归纳和实现可以参考Frame Phoneme Classification with Bidirectional LSTM by Alex Graves,后者有比较清晰的back propagation的公式。
最近两年这个model在speech,language以及multimodal with vision等方面可谓是大展宏图,一再的刷新实验结果,重要工作可以参考:
Speech recognition with Deep Recurrent Neural Networks by Graves
Sequence to Sequence Learning with Neural Networks by Sutskever
Show Attend and Tell by Kelvin Xu
至于具体的实现,希望避免造轮子的可以参考这个非常famous的github:karpathy (Andrej) · GitHub,Andrej Karpathy最近发了很多很有趣的RNN的fun project,可以borrow一些代码。
希望自己造轮子的,可以选择用Theano或者Torch,用画data flow的方法来code整个structure,很简洁实用,我个人一直用Theano,给个好评。:)
当然啦,至于你要研究什么问题,还是具体问题具体分析的好。可以去搜搜有没有研究类似问题的paper,看看目前的最好的技术是什么。Deep Learning不一定是万能的啦。

3. 易语言查找算法,求高人进,我写了一个在文件里查找文本的算法,是这...

不造你是不是要做阅读器

好吧给你个思路 你先把文本长度读出来 取文本长度()这个方法会用吧
然后给它分割成若干部分,比如分割原文本长度的1/2 这个会吧?取文本左边()这个方法。
然后再取文本右边()取到剩下的一半 ,再对这两部分依次重复一次, 每次取一半分割成4部分 然后开四个线程分割换行符或者啥的,再循环查找。要是四部分不够效率继续分下去,分成8个。16个。。。这样是最简单的解决办法 。

4. 文本比较有哪些算法

java比较两个文本文件的不同
RangeDifferencer

public class RangeDifferencer {
private static final RangeDifference[] EMPTY_RESULT= new RangeDifference[0];

/* (non Javadoc)
* Cannot be instantiated!
*/
private RangeDifferencer() {
// nothing to do
}

/**
* Finds the differences between two <code>IRangeComparator</code>s.
* The differences are returned as an array of <code>RangeDifference</code>s.
* If no differences are detected an empty array is returned.
*
* @param left the left range comparator
* @param right the right range comparator
* @return an array of range differences, or an empty array if no differences were found
*/
public static RangeDifference[] findDifferences(IRangeComparator left, IRangeComparator right) {

int rightSize= right.getRangeCount();
int leftSize= left.getRangeCount();
//
// Differences matrix:
// only the last d of each diagonal is stored, i.e., lastDiagonal[k] = row of d
//
int diagLen= 2 * Math.max(rightSize, leftSize); // bound on the size of edit script
int maxDiagonal= diagLen;
int lastDiagonal[]= new int[diagLen + 1]; // the row containing the last d
// on diagonal k (lastDiagonal[k] = row)
int origin= diagLen / 2; // origin of diagonal 0

// script corresponding to d[k]
LinkedRangeDifference script[]= new LinkedRangeDifference[diagLen + 1];
int row, col;

// find common prefix
for (row= 0; row < rightSize && row < leftSize && rangesEqual(right, row, left, row) == true;)
row++;

lastDiagonal[origin]= row;
script[origin]= null;
int lower= (row == rightSize) ? origin + 1 : origin - 1;
int upper= (row == leftSize) ? origin - 1 : origin + 1;

if (lower > upper)
return EMPTY_RESULT;

//System.out.println("findDifferences: " + maxDiagonal + " " + lower + " " + upper);

// for each value of the edit distance
for (int d= 1; d <= maxDiagonal; ++d) { // d is the current edit distance

if (right.skipRangeComparison(d, maxDiagonal, left))
return EMPTY_RESULT; // should be something we already found

// for each relevant diagonal (-d, -d+2 ..., d-2, d)
for (int k= lower; k <= upper; k += 2) { // k is the current diagonal
LinkedRangeDifference edit;

if (k == origin - d || k != origin + d && lastDiagonal[k + 1] >= lastDiagonal[k - 1]) {
//
// move down
//
row= lastDiagonal[k + 1] + 1;
edit= new LinkedRangeDifference(script[k + 1], LinkedRangeDifference.DELETE);
} else {
//
// move right
//
row= lastDiagonal[k - 1];
edit= new LinkedRangeDifference(script[k - 1], LinkedRangeDifference.INSERT);
}
col= row + k - origin;
edit.fRightStart= row;
edit.fLeftStart= col;

//Assert.isTrue(k >= 0 && k <= maxDiagonal);

script[k]= edit;

// slide down the diagonal as far as possible
while (row < rightSize && col < leftSize && rangesEqual(right, row, left, col) == true) {
++row;
++col;
}

//Assert.isTrue(k >= 0 && k <= maxDiagonal); // Unreasonable value for diagonal index

lastDiagonal[k]= row;

if (row == rightSize && col == leftSize) {
//showScript(script[k], right, left);
return createDifferencesRanges(script[k]);
}
if (row == rightSize)
lower= k + 2;
if (col == leftSize)
upper= k - 2;
}
--lower;
++upper;
}
// too many differences
//Assert.isTrue(false);
return null;
}

/**
* Finds the differences among two <code>IRangeComparator</code>s.
* In contrast to <code>findDifferences</code>, the result
* contains <code>RangeDifference</code> elements for non-differing ranges too.
*
* @param left the left range comparator
* @param right the right range comparator
* @return an array of range differences
*/
public static RangeDifference[] findRanges(IRangeComparator left, IRangeComparator right) {
RangeDifference[] in= findDifferences(left, right);
List out= new ArrayList();

RangeDifference rd;

int mstart= 0;
int ystart= 0;

for (int i= 0; i < in.length; i++) {
RangeDifference es= in[i];

rd= new RangeDifference(RangeDifference.NOCHANGE, mstart, es.rightStart() - mstart, ystart, es.leftStart() - ystart);
if (rd.maxLength() != 0)
out.add(rd);

out.add(es);

mstart= es.rightEnd();
ystart= es.leftEnd();
}
rd= new RangeDifference(RangeDifference.NOCHANGE, mstart, right.getRangeCount() - mstart, ystart, left.getRangeCount() - ystart);
if (rd.maxLength() > 0)
out.add(rd);

return (RangeDifference[]) out.toArray(EMPTY_RESULT);
}

//---- private methods

/*
* Creates a Vector of DifferencesRanges out of the LinkedRangeDifference.
* It coalesces adjacent changes.
* In addition, indices are changed such that the ranges are 1) open, i.e,
* the end of the range is not included, and 2) are zero based.
*/
private static RangeDifference[] createDifferencesRanges(LinkedRangeDifference start) {

LinkedRangeDifference ep= reverseDifferences(start);
ArrayList result= new ArrayList();
RangeDifference es= null;

while (ep != null) {
es= new RangeDifference(RangeDifference.CHANGE);

if (ep.isInsert()) {
es.fRightStart= ep.fRightStart + 1;
es.fLeftStart= ep.fLeftStart;
RangeDifference b= ep;
do {
ep= ep.getNext();
es.fLeftLength++;
} while (ep != null && ep.isInsert() && ep.fRightStart == b.fRightStart);
} else {
es.fRightStart= ep.fRightStart;
es.fLeftStart= ep.fLeftStart;

RangeDifference a= ep;
//
// deleted lines
//
do {
a= ep;
ep= ep.getNext();
es.fRightLength++;
} while (ep != null && ep.isDelete() && ep.fRightStart == a.fRightStart + 1);

boolean change= (ep != null && ep.isInsert() && ep.fRightStart == a.fRightStart);

if (change) {
RangeDifference b= ep;
//
// replacement lines
//
do {
ep= ep.getNext();
es.fLeftLength++;
} while (ep != null && ep.isInsert() && ep.fRightStart == b.fRightStart);
} else {
es.fLeftLength= 0;
}
es.fLeftStart++; // meaning of range changes from "insert after", to "replace with"

}
//
// the script commands are 1 based, subtract one to make them zero based
//
es.fRightStart--;
es.fLeftStart--;
result.add(es);
}
return (RangeDifference[]) result.toArray(EMPTY_RESULT);
}

/*
* Tests if two ranges are equal
*/
private static boolean rangesEqual(IRangeComparator a, int ai, IRangeComparator b, int bi) {
return a.rangesEqual(ai, b, bi);
}

/*
* Tests whether <code>right</code> and <code>left</code> changed in the same way
*/
private static boolean rangeSpansEqual(IRangeComparator right, int rightStart, int rightLen, IRangeComparator left, int leftStart, int leftLen) {
if (rightLen == leftLen) {
int i= 0;
for (i= 0; i < rightLen; i++) {
if (!rangesEqual(right, rightStart + i, left, leftStart + i))
break;
}
if (i == rightLen)
return true;
}
return false;
}

/*
* Reverses the range differences
*/
private static LinkedRangeDifference reverseDifferences(LinkedRangeDifference start) {
LinkedRangeDifference ep, behind, ahead;

ahead= start;
ep= null;
while (ahead != null) {
behind= ep;
ep= ahead;
ahead= ahead.getNext();
ep.setNext(behind);
}
return ep;
}
}

下面是一段关于如何使用这些类的简单的测试代码

public class RangeDifferencerTest extends TestCase {

InputStream left = null;
InputStream right = null;

/**
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception {
String file1 = "d:/temp/1.txt";
String file2 = "d:/temp/2.txt";
left = new FileInputStream(new File(file1));
right = new FileInputStream(new File(file2));
super.setUp();
}

/**
* @see junit.framework.TestCase#tearDown()
*/
protected void tearDown() throws Exception {
left.close();
right.close();
super.tearDown();
}

public static void main(String[] args) {
}

/*
* Test method for 'com.greatroad.smbnm.compare.RangeDifferencer.findDifferences(IRangeComparator, IRangeComparator)'
*/
public void testFindDifferences() {
try {
RangeDifference[] rds = RangeDifferencer.findRanges(new LineComparator(left,"GBK"),new LineComparator(right,"GBK"));
if(rds != null ){
for(int i=0; i<rds.length; i++){
RangeDifference rd = rds[i];
int length = rd.leftLength();
System.out.println(
"kind = "+rd.kind()
+",left["+rd.leftStart()+"-"+rd.leftEnd()
+"],right["+rd.rightStart()+"-"+rd.rightEnd()+"]");
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}

5. 文本分类的算法是属于机器学习么

经过算法不断自己调优就可以算机器学习,简单理解就是算法来进行分类而且效果很好
如果有标签属于监督学习,没有标签属于无监督学习

6. k-means聚类算法的java代码实现文本聚类

K-MEANS算法:
k-means 算法接受输入量 k ;然后将n个数据对象划分为 k个聚类以便使得所获得的聚类满足:同一聚类中的对象相似度较高;而不同聚类中的对象相似度较小。聚类相似度是利用各聚类中对象的均值所获得一个“中心对象”(引力中心)来进行计算的。

k-means 算法的工作过程说明如下:首先从n个数据对象任意选择 k 个对象作为初始聚类中心;而对于所剩下其它对象,则根据它们与这些聚类中心的相似度(距离),分别将它们分配给与其最相似的(聚类中心所代表的)聚类;然后再计算每个所获新聚类的聚类中心(该聚类中所有对象的均值);不断重复这一过程直到标准测度函数开始收敛为止。一般都采用均方差作为标准测度函数. k个聚类具有以下特点:各聚类本身尽可能的紧凑,而各聚类之间尽可能的分开。

具体如下:
输入:k, data[n];
(1) 选择k个初始中心点,例如c[0]=data[0],…c[k-1]=data[k-1];
(2) 对于data[0]….data[n], 分别与c[0]…c[n-1]比较,假定与c[i]差值最少,就标记为i;
(3) 对于所有标记为i点,重新计算c[i]=/标记为i的个数;
(4) 重复(2)(3),直到所有c[i]值的变化小于给定阈值。

算法实现起来应该很容易,就不帮你编写代码了。

7. 谁懂文本滑动算法

5日滑动平均算法,具体一些

8. 求一段加密后的文本内容的原文及采用的加密算法

两次MD5加密后的组合。
例:原参数为id=100&pid=200
加密方法:先将前面的“100”加密,再将后面的200加密,两个参数的加密字符要写进数据库,然后两段代码组合成64位。
程序读取到这么长的代码后,用函数把代码分解,分别去匹配库里的加密字符串,便可以得到相应的数据(ID,PID)。
你想解密的话,还是算了吧,加5000分也没人能解出来。

9. knn算法用来文本分类怎么样

一般

10. 目前最好的文本分类算法

文本分类问题与其它分类问题没有本质上的区别,其方法可以归结为根据待分类数据的某些特征来进行匹配,当然完全的匹配是不太可能的,因此必须(根据某种评价标准)选择最优的匹配结果,从而完成分类。

热点内容
诺基亚密码忘了打什么电话 发布:2024-09-17 03:27:09 浏览:555
树深度优先算法 发布:2024-09-17 03:26:58 浏览:472
跳转页源码 发布:2024-09-17 03:13:05 浏览:543
html文件上传表单 发布:2024-09-17 03:08:02 浏览:785
聊天软件编程 发布:2024-09-17 03:00:07 浏览:726
linuxoracle安装路径 发布:2024-09-17 01:57:29 浏览:688
两个安卓手机照片怎么同步 发布:2024-09-17 01:51:53 浏览:207
cf编译后没有黑框跳出来 发布:2024-09-17 01:46:54 浏览:249
安卓怎么禁用应用读取列表 发布:2024-09-17 01:46:45 浏览:524
win10设密码在哪里 发布:2024-09-17 01:33:32 浏览:662