GithubHelp home page GithubHelp logo

keywordfinder's Introduction

Automatic keyword extraction

As an Insight Data Science Fellow, I completed a 3-week project that involved building a keyword extraction algorithm. Given a block of text as input, the algorithm selects keywords that describe what the text is about. Keywords are useful, compact descriptions of the original text, and they are widely used in information retrieval applications.

Background

For this project, I partnered with URX, a San Francisco-based startup in the mobile advertising space. URX matches advertisers and content providers, in a context-specific way. For example, if the content consists of a news article about hip-hop music, URX will serve ads for hip-hop albums on Spotify, a music streaming service. URX accomplishes this matching by extracting keywords from a content page, using those keywords to search a database of advertisers, and then serving the best matching ad.

In my project, I focused on the keyword extraction step, and I built a prototype keyword extractor for URX. The deliverables were: (i) an algorithm for keyword extraction; and (ii) Python scripts to implement the algorithm. To learn about the algorithm I developed, check out the project page.

Test it out!

curl --request POST \
  --url http://keywordfinder.herokuapp.com/api \
  --header 'accept-language: application/json' \
  --header 'cache-control: no-cache' \
  --header 'content-type: application/json' \
  --header 'postman-token: 04cb8b00-7deb-6ac1-018d-94d9c4906cbf' \
  --header 'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.87 Safari/537.36' \
  --data '{"text": "Reeling from their losses in Tuesday’s Democratic and Republican primaries, Senator Bernie Sanders of Vermont and Senator Ted Cruz of Texas abruptly reordered their campaigns on Wednesday, aiming to preserve some small hope that the race might yet turn in their favor.Mr. Cruz named a running mate, Carly Fiorina, to help bring down Donald J. Trump, the Republican favorite, and both spoke of Mr. Trump in the language of relentless opposition, casting him as a sinister figure who must not be allowed to become president. On the Democratic side, Mr. Sanders said he would scale back his upstart bid for the White House and lay off hundreds of campaign workers, a measure seemingly intended to extend the life of his candidacy but not to prepare for a general election. In an interview, Mr. Sanders acknowledged in the strongest terms yet that Hillary Clinton’s delegate lead might have closed off his path to the nomination, and he was less combative toward his party’s front-runner in his moment of apparent defeat, taking a tone of cold realism, if not quite resignation. Stymied in his efforts this week to challenge Mrs. Clinton’s dominance in the urban Northeast, Mr. Sanders said he would now refocus his efforts chiefly on the June 7 primary in California, a state laden with both delegates and political symbolism. By winning there, he said, he hoped to strengthen his hand ahead of the Democratic convention in Philadelphia, where he would push his core priorities into the party platform. “If we can win the largest state in this country, that will send a real message to the American people,” Mr. Sanders said, “and to the delegates that this is a campaign that is moving in the direction it should.” The Sanders campaign said late Wednesday that it would continue to maintain a staff of more than 300 as the race moved toward California. The campaign had roughly 1,000 workers during the initial nominating contests.  Mr. Sanders did not rule out a comeback before the end of primary voting in June. But he has appeared to tone down his antagonism of Mrs. Clinton in recent days, abandoning his brief attacks on her qualifications for the presidency and instead focusing on her policy stances and ties to Wall Street. If Mr. Sanders seemed on Wednesday to bow to political reality on the Democratic side — and to Mrs. Clinton’s apparent inevitability as the party’s nominee — Mr. Cruz took a far more defiant line in the Republican race. Walloped by Mr. Trump in the last six primaries and lagging behind him in polls before next week’s contest in Indiana, Mr. Cruz made a daring but somewhat desperate announcement: that in the event of his nomination, Mrs. Fiorina, the former Hewlett-Packard executive, would be his vice-presidential running mate. Appearing alongside Mrs. Fiorina in Indianapolis, Mr. Cruz delivered a stemwinder of a speech, castigating Mr. Trump as an untrustworthy narcissist. He and Mrs. Fiorina jointly criticized the news media for rushing to treat Mr. Trump’s victory in the nomination fight as a foregone conclusion. The Republican race, Mrs. Fiorina said, was a struggle “for the soul of our party and the future of our nation.” By rushing out a vice-presidential pick before the Indiana vote, which is becoming make-or-break for his candidacy, Mr. Cruz opted to tear open his party’s divisions even more widely, rather than to stand down in view of Mr. Trump’s growing strength. Mr. Cruz’s criteria for a pick, in his telling, seemed to be aimed squarely at Mr. Trump. “Do they think through decisions in a rash and impulsive way?” he asked. “Do they pop off the handle at whatever strikes them at any given moment?” He held up Mrs. Fiorina as someone who knows “where jobs come from.” Mr. Cruz’s selection of Mrs. Fiorina may present a perilous challenge for Mr. Trump, who is grappling with mounting criticism of his derisive remarks about women, including his repeated claims that Mrs. Clinton’s sole political asset is “the woman’s card.” Mindful of the gender gap often evident in Mr. Trump’s polling, Cruz allies hope that Mrs. Fiorina will prove a capable foil to him, as she did while besting him in a series of debate exchanges during her own candidacy. Since endorsing Mr. Cruz last month, Mrs. Fiorina has proved to be an eager surrogate, attacking Mr. Trump and Mrs. Clinton with zeal. Mr. Trump, viewed unfavorably by most women in general election polls, has clashed savagely with Mrs. Fiorina in the past. He has mocked her business record, her voice and even her looks. “Look at that face,” Mr. Trump said in an interview with Rolling Stone magazine last summer. “Would anyone vote for that?” Another slashing comment directed at Mrs. Fiorina’s appearance or gender could have grave consequences for Mr. Trump, especially with female voters he would need to win over to compete in the fall. Mr. Trump responded to the surprise announcement with a degree of restraint. Referring to the “new relationship” between “Cruz and Carly,” Mr. Trump shook his head and raised his eyebrows as he dismissed the move. “He has set a record,” Mr. Trump said of his opponent. “He is the first presidential candidate in the history of this country who’s mathematically eliminated from becoming president who chose a vice-presidential candidate.” Mr. Cruz’s gambit was received chiefly as an act of beleaguered improvisation — the political equivalent of a student pulling a fire alarm to avoid an exam. In the short term, Mr. Cruz may have succeeded in shifting the focus away from Mr. Trump’s success in the last two rounds of voting, and from his own wheezing alliance with Gov. John Kasich of Ohio, who agreed to clear out of Indiana if Mr. Cruz withdrew from competition in Oregon and New Mexico. Yet his partnership with Mrs. Fiorina may prove of limited value if Mr. Trump clobbers them both in Indiana, where 57 delegates are at stake. Mr. Trump already leads Mr. Cruz by more than 400 delegates, and has gathered more than three-quarters of the delegates he needs to clinch the Republican nomination. Mr. Cruz acknowledged in his speech on Wednesday that he no longer had a chance of winning the 1,237 delegates required to become the nominee, but said he still planned to challenge Mr. Trump in an open convention. Subscribe for updates on the 2016 presidential race, the White House and Congress, delivered to your inbox Monday - Friday. With his announcement, Mr. Cruz becomes the first candidate in 40 years — since Ronald Reagan in 1976 — to name a running mate before capturing his party’s nomination. Far more conventional is Mr. Sanders’s shift toward a strategy of dogged and benign persistence, rather than aggressive confrontation with Mrs. Clinton. Candidates for president routinely scale back their campaigns but forge ahead because they hope to advance a specific policy agenda, or out of a sense of obligation to their supporters. Mrs. Clinton, for one, insisted on fighting the 2008 Democratic race all the way through the last day of primary voting, even after Barack Obama had gained a permanent upper hand in the competition for delegates. Yet few losing candidates in recent memory have generated the kind of electric energy within the Democratic base that Mr. Sanders has in the 2016 election. Democratic leaders are especially sensitive to his following among young people, who have voted for him by staggering margins, and whose support Mrs. Clinton may rely on against Mr. Trump in the November election. Even if Mr. Sanders shies away from direct conflict with Mrs. Clinton, he could still be an irksome presence in the race. He is likely to win several primaries in May, and a large-scale effort in California could pressure Mrs. Clinton to spend time and money there to forestall an embarrassing upset. But unlike Mr. Trump, who appears determined to batter Mr. Cruz and Mr. Kasich into submission, Mrs. Clinton and her allies have taken a gingerly approach to Mr. Sanders in what seem to be the waning days of his campaign. They have urged Mr. Sanders to sand down the sharpest edges of his arguments against Mrs. Clinton and begin to prepare the party for a moment of coming together in Philadelphia. Gov. Jack Markell of Delaware, a Clinton supporter, said Democrats hoped for “a somewhat rapid conclusion” to the primaries, but viewed withdrawing from the presidential race as a “personal decision” for Mr. Sanders. “Obviously, as you get to this point, you want to see all Democrats focused on the Republicans and not focused on each other,” Mr. Markell said. Mr. Sanders, he added, “certainly believes that electing one of these Republicans as president would be a real nightmare for the country.”"}'

Running the code

To get started, run the example:

python example.py inspec.txt

To evaluate the algorithm on Crowd500 dataset from Marujo et al., 2012, run:

python evaluatemodel.py 

Note that the algorithm is trained on the train set of Crowd500, but it is evaluated only on the test set of Crowd500.

For comparison, I provide two baselines: random and AlchemyAPI. The random baseline selects words at random from the given text, whereas the AlchemyAPI baseline consists of keywords returned by the Alchemy analytics engine. The top-15 keyword evaluation methodology is similar to that of Jean-Louis et al., 2014.

python evaluaterandom.py 
python evaluatealchemy.py 

My algorithm (f1 score = 23.95) outperforms AlchemyAPI (f1 score = 21.19), and beats the random baseline quite easily (f1 = 8.41). It is worth noting that my algorithm was trained on the Crowd500 train set, whereas the Alchemy keyword extractor (presumably) was not. Additionally, Alchemy excels at returning keyphrases rather than keywords, which this benchmark does not assess.

keywordfinder's People

Contributors

lvsh avatar freeslugs avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.