mini-ai / maker.html
byjameson's picture
mini-ai: Tiny AI Maker
f82deb4 verified
Raw History Blame Contribute Delete
113 kB
<!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Tiny AI Maker — train a classifier in your browser</title> <style> :root { --bg:#0f1115; --panel:#171a21; --fg:#e8e6e3; --muted:#9aa0aa; --accent:#6ee7b7; --warn:#fbbf24; --line:#232733; } * { box-sizing: border-box; } body { margin:0; background:var(--bg); color:var(--fg); font:16px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; } main { max-width: 900px; margin:0 auto; padding: 44px 22px 80px; } h1 { font-size: clamp(30px, 5vw, 46px); line-height:1.05; margin: 14px 0 10px; letter-spacing:-0.8px; } h2 { font-size: 20px; margin: 0 0 10px; } p { margin: 0 0 12px; } .lead { color:var(--muted); font-size:18px; margin:0 0 26px; max-width: 740px; } .badge { display:inline-block; background:var(--accent); color:#06281d; font-weight:800; font-size:14px; letter-spacing:0.5px; padding:6px 10px; border-radius:6px; } .panel { background:var(--panel); border:1px solid var(--line); border-radius:12px; padding:18px; margin:16px 0; } .muted { color:var(--muted); font-size:13px; } textarea { width:100%; background:#0d1015; color:var(--fg); border:1px solid var(--line); border-radius:8px; padding:12px; font:inherit; resize:vertical; } input[type=file] { color:var(--muted); margin-top:10px; } button { border:0; border-radius:8px; cursor:pointer; font:inherit; } .go { margin-top:12px; padding:12px 16px; background:var(--accent); color:#06281d; font-weight:750; font-size:15px; } .go:hover { filter:brightness(1.06); } .chip { border:1px solid var(--line); background:#0d1015; color:var(--fg); padding:8px 10px; border-radius:8px; cursor:pointer; font-size:14px; } .chip:hover { border-color:#3a4150; } .chips { display:flex; gap:8px; flex-wrap:wrap; margin-top:10px; } select { background:#0d1015; color:var(--fg); border:1px solid var(--line); border-radius:8px; padding:8px; font:inherit; } .metrics { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; margin:12px 0; } .metrics div { text-align:center; } .metrics span { display:block; font-size:24px; font-weight:750; color:var(--accent); } .metrics label { font-size:12px; color:var(--muted); } table { width:100%; border-collapse:collapse; font-size:14px; margin-top:10px; } th, td { text-align:left; padding:6px; border-bottom:1px solid var(--line); } th { color:var(--muted); font-weight:600; font-size:12px; } td.n { text-align:right; font-variant-numeric:tabular-nums; } td.good { color:var(--accent); font-weight:700; } .cvhead { margin-top:12px; font-size:14px; } .verdict { font-size:22px; font-weight:750; margin:14px 0 8px; } .bar-row { display:grid; grid-template-columns: 110px 1fr 54px; gap:8px; align-items:center; font-size:13px; margin:5px 0; } .bar { height:10px; background:#0d1015; border-radius:5px; overflow:hidden; } .bar > i { display:block; height:100%; background:var(--accent); width:0; } .bar-row span:last-child { text-align:right; color:var(--muted); } .err { color:#fca5a5; } footer { margin-top:30px; color:var(--muted); font-size:13px; } a { color:var(--accent); } @media (max-width: 620px) { .metrics { grid-template-columns:repeat(2,1fr); } } </style> </head> <body> <main> <header> <div class="badge">browser-only</div> <h1>Tiny AI Maker</h1> <p class="lead">Bring a small labelled text dataset. This page fits a Complement Naive Bayes in your browser, shows held-out accuracy with a confidence interval, an optional 5-fold CV with out-of-fold Brier/ECE, the int8 weight size and the example size, and exports a single HTML file, a QR, a favicon, a WAV or a PDF model card. No data leaves the page.</p> </header> <section class="panel"> <h2>1. Data</h2> <p class="muted">CSV/TSV with two columns: <code>text,label</code>. Quote fields that contain commas. JSONL with <code>{"text":"...","label":"..."}</code> also works.</p> <textarea id="data" rows="8" placeholder="text,label&#10;The movie was great,positive&#10;The plot was dull,negative"></textarea> <input id="file" type="file" accept=".csv,.tsv,.jsonl,.txt,.json"> <div class="chips"> <button class="chip" id="sample">Load AG News sample</button> <button class="chip" id="sms">Load SMS spam sample</button> <button class="chip" id="parse">Parse data</button> </div> <p class="muted" id="dataInfo"></p> </section> <section class="panel"> <h2>2. Train</h2> <p class="muted">The model is the selected examples; the training code is shared. A smaller budget means a smaller artifact and usually a little less accuracy.</p> <label class="muted" for="budget">Artifact budget</label> <select id="budget"> <option value="50">50 examples</option> <option value="100" selected>100 examples</option> <option value="250">250 examples</option> <option value="500">500 examples</option> <option value="1000">1,000 examples</option> <option value="all">All training rows</option> </select> <button class="go" id="train">Train</button> <p class="muted" id="trainInfo">Parse some data first.</p> </section> <section class="panel"> <h2>3. Result</h2> <div id="metrics"></div> <div id="confusion"></div> <button class="chip" id="cvgo" disabled>Run 5-fold CV + calibration</button> <div id="cvout"></div> <div id="try" style="display:none"> <label class="muted" for="text">Try it</label> <textarea id="text" rows="3">The movie was great</textarea> <button class="go" id="classify">Classify</button> <div id="out"></div> </div> <button class="go" id="export" disabled>Download single HTML</button> <button class="chip" id="cardgo" disabled>Download model card</button> <button class="chip" id="pdfgo" disabled>Download PDF card</button> <p class="muted" id="exportInfo"></p> </section> <section class="panel"> <h2>4. QR export</h2> <p class="muted">Pack the learned weights into a URL/QR, a 32×32 PNG favicon, or an 8-bit WAV. Small vocabularies fit; the page tries a smaller vocabulary if needed. The viewers are <code>qr.html</code>, <code>favicon.html</code>, and <code>audio.html</code>.</p> <button class="go" id="qrgo" disabled>Build QR</button> <button class="chip" id="favgo" disabled>Download favicon PNG</button> <button class="chip" id="wavgo" disabled>Download WAV</button> <div id="qrout"></div> </section> <footer> Built with the same <a href="mini-ai.html">130 KB AI</a> recipe. The artifact is the data; the training procedure is the shared code. Nothing is uploaded. </footer> </main> <script src="qrcode.min.js"></script> <script> const SAMPLE = [{"text":"VW Exec Says Job Cuts May Be Necessary (AP) AP - The head of personnel at Volkswagen AG said the automaker will have to make dramatic reductions in jobs in Germany if it doesn't get the labor-cost savings it wants in ongoing wage talks, a newspaper reported Wednesday.","label":"Business"},{"text":"Stocks May Open Lower on Jobs Report NEW YORK - U.S. stocks are seen flat to slightly lower at the open Monday as investors grapple with Friday's disappointing jobs report...","label":"Business"},{"text":"Palestinian Zakah to Combat Poverty A cohort of Palestinian intellectuals proposed setting up a central Zakah fund to channel the alms into productive projects ","label":"Business"},{"text":"Iraqi Oil Exports Not Cut by Yesterday #39;s South Pipeline Breach Iraq is exporting oil normally from the south through its Persian Gulf terminals after a pipeline was breached yesterday, the UK military and two shipping agents said.","label":"Business"},{"text":"Marsh McLennan to Lay Off 3,000 Marsh McLennan said today that it would lay off roughly 5 percent of its work force, as it moved to right itself after being accused of bid-rigging.","label":"Business"},{"text":"Feds, provinces prepare to reshape the fiscal map in eqaulization talks (Canadian Press) Canadian Press - OTTAWA (CP) - The federal government is promising the most sweeping overhaul to date of the 47-year-old equalization program in an effort to guarantee provinces more stable annual funding.","label":"Business"},{"text":"Congress Probes Insurance Industry Scandal (AP) AP - Congress is examining the scandal rippling through the insurance industry, with its largest brokerage accused of bid rigging and price fixing amid high-level resignations, employee layoffs and guilty pleas by some executives.","label":"Business"},{"text":"No SEC Decision on Google IPO Paperwork SAN JOSE, Calif. - Google Inc.'s plans to move ahead with its initial public stock offering ran into a roadblock when the Securities and Exchange Commission didn't approve the Internet search giant's regulatory paperwork as requested...","label":"Business"},{"text":"Business 'booms' for rural crafts Craftspeople could soon overtake farmers as the biggest contributors to the rural economy, a report says.","label":"Business"},{"text":"Group Cites Electronic Voting Problems (AP) AP - The record use of electronic voting machines on Nov. 2 led to hundreds of voting irregularities and shows the need for higher standards, a voting rights group said Thursday.","label":"Business"},{"text":"Durable Goods, Lower Oil Lift Stocks NEW YORK - Stocks edged higher Friday as a dip in oil prices and a satisfactory report on durable goods orders cheered investors at the end of a losing week. In late morning trading, the Dow Jones industrial average rose 27.14, or 0.3 percent, to 10,066.04...","label":"Business"},{"text":"Economists: Bush, Kerry Job Plans Lacking WASHINGTON - President Bush says his economic policies, including billions of dollars in tax cuts, are helping to create new jobs. But not the millions he promised...","label":"Business"},{"text":"3rd German Arrested in Probe Into Arms Trade The man is suspected of selling high-tech equipment on the nuclear black market and is the third German businessman named as a suspect in the past month in an investigation into the trade in several countries.","label":"Business"},{"text":"Budget math deflating many Bush initiatives (USATODAY.com) USATODAY.com - A number of spending initiatives promoted by President Bush as he seeks re-election are set to get less money than he wants from the Republicans who control Congress.","label":"Business"},{"text":"4 Held In UK For Trying To Buy N-Material After Papers &lt;b&gt;...&lt;/b&gt; London, Sept. 26 (NNN): After a sting operation involving a newspaper and the sleuths of British intelligence, the London police has arrested four Muslim men posing as businessmen who were trying to buy radioactive material.","label":"Business"},{"text":"Crude Oil Prices Top \\$50 Per Barrel LONDON - Crude oil topped the psychological milestone of \\$50 per barrel Tuesday for the first time, and a Saudi Arabian oil official said the world's largest petroleum exporter would raise its production capacity by 15 percent in a bid to calm prices. Analysts said instability in the Middle East, political unrest in Nigeria, Africa's top oil exporter, and damage to U.S...","label":"Business"},{"text":"Managers Move Some Funds to Europe, Asia (Reuters) Reuters - U.S. fund managers seem inclined not\\to make any big shifts in allocations among the major asset\\classes, but a new Reuters poll shows money moving into Europe\\outside of the Eurozone and into non-Japan Asia.","label":"Business"},{"text":"British Airways cancels 966 flights in next three months (AFP) AFP - British Airways said it planned to cancel almost 1,000 flights in the next three months.","label":"Business"},{"text":"Lufthansa reaches wages agreement German airline Lufthansa reaches a deal with unions on pay and working hours for its ground staff.","label":"Business"},{"text":"Andrew Smith resigns from Cabinet Work and Pensions Secretary Andrew Smith has resigned from the Cabinet, says Downing Street.","label":"Business"},{"text":"Hanes Opens Unmentionables Market in China (AP) AP - Hanes is entering the lucrative consumer market of the world's most populous nation, China.","label":"Business"},{"text":"Bush Spends Half of #36;75M Grant in Sept. (AP) AP - President Bush burned through more than half of his #36;75 million government grant to cover his general-election campaign costs in September, leaving him with just under #36;37 million left for the final month before the Nov. 2 election.","label":"Business"},{"text":"Junk mailers get the human touch Online criminals are exploiting human hopes and fears to spread spam and viruses.","label":"Business"},{"text":"Report: Russia May Give Yukos Unit Warning (AP) AP - Russia's natural resources minister said Friday that he thought his ministry would give the main production unit of the battered Yukos oil company a three-month warning before pulling its drilling licenses, the Interfax news agency reported.","label":"Business"},{"text":"Greenspan warns over US deficit Federal Reserve chief Alan Greenspan says the US trade deficit cannot be sustained indefinitely.","label":"Business"},{"text":"Illegal migrants' Social Security payments out of reach MEXICO CITY -- For the 14 years he worked as an undocumented migrant in the United States, Carmelo Rivera saw up to \\$30 deducted each week from the \\$300 to \\$500 he earned as a vineyard worker. The deductions were supposed to pay for his retirement.","label":"Business"},{"text":"Japanese Electronics Makers Raise Outlook (AP) AP - Japanese electronics makers Toshiba Corp. and Hitachi Ltd. raised their earnings outlooks for the fiscal first half Friday on rising global demand for electronics products.","label":"Business"},{"text":"VW locked in tough talks as warning strikes continue HANOVER - Management at Volkswagen and union leaders were locked in tough wage talks Tuesday as thousands of workers at Europe #39;s largest car maker staged more warning strikes.","label":"Business"},{"text":"The Fire This Time Eri Suheri can be seen most mornings in the same spot in front of the Metropolitan Medical Center, an upscale hospital located in the heart of Jakarta #39;s Kuningan business district.","label":"Business"},{"text":"Barroso makes limited changes to Commission Incoming European Commission President Jose Manuel Duro Barroso yesterday announced the new line-up of his EU executive team, aimed at resolving a row that has left Brussels in limbo.","label":"Business"},{"text":"Johnny Cash auction closes at \\$4m Johnny Cash's instruments and possessions raise almost \\$4m (2.2) after a three-day auction in New York.","label":"Business"},{"text":"Supreme Court Bars Anti-Abortion Group Ad (AP) AP - The Supreme Court declined Tuesday to allow a Wisconsin anti-abortion group to run political ads this fall that criticize Democrats.","label":"Business"},{"text":"Egypt to let foreign companies manage state enterprises (AFP) AFP - Egypt is ready to let foreign companies manage state-owned businesses but will not give up control of those it sees as strategic, President Hosni Mubarak's spokesman said.","label":"Business"},{"text":"Oil Prices Top \\$53 a Barrel, Set Record Oil futures prices advanced to a new high Monday as a strike began in Africa's largest exporter of crude, exacerbating global supply concerns at a time of strong demand and reduced output in the hurricane-ravaged Gulf of Mexico. Worries about Russian oil supplies also persist as oil giant Yukos, already struggling to repay a multibillion-dollar back-tax bill, got hit Monday with \\$1.34 billion in fines...","label":"Business"},{"text":"Canada Hopes New Beef Rules Will Win Over Japan (Reuters) Reuters - Canada has positioned itself ahead of the\\United States to regain share in the lucrative Japanese beef\\market, thanks to strict new rules aimed at preventing mad cow\\disease, Agriculture Minister Andy Mitchell said on Wednesday.","label":"Business"},{"text":"BTC launches Bulgaria's third GSM network (AFP) AFP - The Bulgarian Telecommunications Company (BTC) launched the country's third GSM mobile phone network, ringing in the new service by phoning from Sofia to a landline in Bourgas on the Black Sea.","label":"Business"},{"text":"Officials Warn of Major Flu Shot Shortages LONDON - U.S. health officials warned Tuesday of major flu shot shortages after British health officials abruptly pulled the license of the maker of half the U.S...","label":"Business"},{"text":"BBC says it was tricked into bogus story The BBC admitted Friday it was tricked into reporting that a US company accepted responsibility for the world #39;s worst industrial accident.","label":"Business"},{"text":"Senate Confirms Treasury's Bitsberger (Reuters) Reuters - The U.S. Senate on Sunday confirmed\\Timothy Bitsberger as assistant secretary for financial\\markets, the key debt market post in the Treasury Department.","label":"Business"},{"text":"Japan Cuts Second-Quarter GDP Estimate to 1.3 Pace (Update9) Japan unexpectedly cut its estimate for second-quarter economic growth to a 1.3 percent annual pace, the slowest in more than a year, as manufacturers slashed inventories.","label":"Business"},{"text":"Paris Club Agrees on Iraq Debt Reduction (AP) AP - A French Finance ministry spokesman said the Paris Club of creditor nations had reached deal Sunday to write off 80 percent of the debts Iraq owes them.","label":"Business"},{"text":"Finance ministers meet to settle dispute over offshore oil revenue (Canadian Press) Canadian Press - OTTAWA (CP) - Finance Minister Ralph Goodale sat down Friday with his counterparts from Newfoundland and Nova Scotia to try to work out a deal on the sharing of offshore oil and gas revenue.","label":"Business"},{"text":"Eurozone data to show sliding business confidence: economists (AFP) AFP - Eurozone figures to be released this week should show business confidence beginning to slide again owing to concern over slowing growth and the strong euro, economists said.","label":"Business"},{"text":"Brazil's Economy Expands 6.1 Percent in 3Q Brazil's economy expanded 6.1 percent in the third quarter compared to same period a year ago, lifted by exports and rising domestic consumer demand, the government said Tuesday.","label":"Business"},{"text":"Brazilian Police Raid Kroll, Make Arrests Police raided the Brazilian offices of international security consultant Kroll Inc., seizing evidence and arresting five employees amid allegations Kroll illegally spied in a probe of a bitter corporate dispute.","label":"Business"},{"text":"Total control: PM seizes the Senate JOHN Howard yesterday ended 8 years of Coalition frustration by winning outright control of the Senate. His breakthrough came after Nationals candidate Barnaby Joyce ","label":"Business"},{"text":"IRS: Rose Owes Nearly \\$1M in Unpaid Taxes MIAMI - Pete Rose is back in trouble with the Internal Revenue Service, which says the baseball great owes nearly \\$1 million in unpaid taxes. The IRS filed a federal tax lien in Broward County on Tuesday alleging that baseball's all-time hits king owes \\$973,693.28 in back taxes from 1997 to 2002...","label":"Business"},{"text":"Nikkei Opens Higher Led by Tech Stocks (Reuters) Reuters - Tokyo's Nikkei share average was up 0.56\\percent in early morning trade on Tuesday as another jump in\\U.S. technology shares encouraged investors to step up buying\\in local counterparts such as Advantest Corp.","label":"Business"},{"text":"Vodafone interim profits dip, dividend hiked (AFP) AFP - Mobile telephone giant Vodafone reported a two percent fall in half-year underlying profits as the group added 7.4 million new customers.","label":"Business"},{"text":"Japanese carrier KDDI to tie up with BT on data communications (AFP) AFP - Japan's number two telecoms operator KDDI said it had agreed with major British carrier BT to join hands on international data communications services for corporate clients.","label":"Business"},{"text":"Diplomatic push on N Korea talks Intense diplomatic efforts are under way to persuade North Korea to give up its nuclear weapons programme.","label":"World"},{"text":"After Arafat, hope - and a job for Europe BERLIN I never met Yasser Arafat, because I never wanted to meet him. Despite several invitations, I have always preferred to spend my time in places where people exchange ideas that go beyond ideology, where ","label":"World"},{"text":"Bush and Pakistani Talk, Skirting Army Role resident Bush spoke for an hour with President Pervez Musharraf of Pakistan yesterday morning in a conversation devoted largely to the hunt for Osama bin Laden and terror groups, administration ","label":"World"},{"text":"Another oil-food scandal emerges UN Secretary-General Kofi Annan said yesterday he was disappointed in his son for accepting payments from a key contractor in the oil-for-food program for more than four years longer than had been previously acknowledged.","label":"World"},{"text":"Bush to Aid 'Moderate' Parties in Iraq Election WASHINGTON (Reuters) - The Bush administration plans to give strategic advice, training and polling data to what it deems as \"moderate and democratic\" Iraqi political parties with candidates running in the country's upcoming elections, government documents show.","label":"World"},{"text":"The Terrorist Statesman Took Peace Nowhere Yasser Arafat #39;s last days on earth, a subject of intense interest throughout much of the world, have evoked mixed emotions in the country that was his life #39;s obsession: Israel.","label":"World"},{"text":"Triumphant Olympics End With Pride, Relief ATHENS, Greece - Efharisto! A nervous world learned the Greek word for thank you and repeated it endlessly at an astonishingly successful Athens Olympics that quelled fears, surprised skeptics and greatly honored the birthplace of the games. Efharisto, Athens, for architectural masterpieces of stadiums and arenas that showcased record performances...","label":"World"},{"text":"C #39;wealth boss lays off from criticising Musharraf over uniform &lt;b&gt;...&lt;/b&gt; World News: Islamabad, Oct 22 : Commonwealth general secretary Don McKinnon today kept himself away from criticising Pakistan President Pervez Musharraf for simultaneously holding the post of Army Chief.","label":"World"},{"text":"Navy commander ordered back to UK The captain of a Royal Navy warship is removed during a tour of duty to the Gulf amid allegations of bullying.","label":"World"},{"text":"A Leap at Freedom for Afghan Wives Three years after the fall of the Taliban, women remain subject to many legal, religious and cultural restrictions and domestic violence is endemic.","label":"World"},{"text":"Delay in Releasing the French The optimism that Paris expressed, at the end of last week, concerning releasing the kidnapped French journalists Chesnot and Malbrunot in Iraq, turned into caution at the beginning of this week.","label":"World"},{"text":"Japan, China Leaders Agree to Meeting The leaders of Japan and China agreed to a one-on-one meeting on the sidelines of a summit, overcoming a diplomatic impasse between the Asian powers that have been increasingly at odds. The breakthrough came as ministers for 21 Pacific Rim economics pledged Thursday work hard for the passage of a global trade treaty.","label":"World"},{"text":"Nine-year-old Afghan boy in critical condition after heart valve surgery (Canadian Press) Canadian Press - TORONTO (CP) - A nine-year-old boy from Afghanistan who came to Canada to have life-saving surgery was in critical condition after undergoing heart valve surgery Friday.","label":"World"},{"text":"Daschle packs up after 26 years on Hill (USATODAY.com) USATODAY.com - His elegant, red-walled Capitol office is filled with boxes of memorabilia and photos and artwork in bubble wrap. At the end of this week, Senate Minority Leader Tom Daschle, D-S.D., will close the doors for the last time and leave behind the view of the National Mall that he has enjoyed for a decade.","label":"World"},{"text":"Defense lawyer in Hamburg Sept. 11 trial seriously hurt The lead attorney defending an accused helper of the Sept 11 suicide pilots at his Hamburg retrial was seriously injured in a motorcycle accident, said his office, throwing into question how the trial will proceed.","label":"World"},{"text":"Canada considers fate of suspected NKorean refugees in China &lt;b&gt;...&lt;/b&gt; Canada is facing a diplomatic headache after a group of suspected North Koreans broke into the Canadian Embassy in the Chinese capital, Beijing, on Wednesday.","label":"World"},{"text":"Pakistan in #39;al-Qaeda #39; arrests At least five suspected terrorists, with alleged links to al Qaeda, have been arrested in Pakistan. It is claimed they had been plotting to launch suicide attacks on government leaders and the US Embassy.","label":"World"},{"text":"Chechnya goes to polls; man blows himself up in Grozny Moscow, Aug. 29 (PTI): An unidentified man blew himself up today outside a polling station in Grozny during presidential elections in war-torn Caucasian province of Chechnya.","label":"World"},{"text":"President Prays at Menorah Lighting (AP) AP - At a menorah-lighting ceremony Thursday on the third night of Hanukkah, President Bush prayed for the safety and quick return of U.S. soldiers serving in Iraq.","label":"World"},{"text":"Venezuelans vote on Chavez rule A referendum is under way in Venezuela to decide if President Hugo Chavez should remain in office.","label":"World"},{"text":"Pakistani Forces Rescue Chinese Hostage Pakistani tribal elders hold a meeting to discuss the release of Chinese engineers in Barwand of South Waziristan, Pakistan along Afghanistan border on Tuesday, Oct. 12, 2004.","label":"World"},{"text":"Peru to Again Seek Fujimori Extradition from Japan (Reuters) Reuters - Peru will submit a second request to\\Japan to extradite former President Alberto Fujimori to face\\charges of corruption, the Peruvian Embassy said Friday.","label":"World"},{"text":"US Court to Decide Sentencing, Death Penalty Cases (Reuters) Reuters - The U.S. Supreme Court begins a new\\term on Monday that will decide important cases on federal\\sentencing rules, the death penalty for juveniles and the\\medical use of marijuana.","label":"World"},{"text":"Japan to confirm what Annan meant by saying Iraq war illegal TOKYO - Japan will try to confirm what UN Secretary General Kofi Annan meant by reportedly saying the US-led invasion of Iraq was an illegal act, top government spokesman Hiroyuki Hosoda said Thursday.","label":"World"},{"text":"Bin Laden Deputy Purportedly Seeks Strikes DUBAI, United Arab Emirates - An audio tape purportedly released by Osama bin Laden's deputy calls for attacks on U.S. and British interests everywhere, according to a broadcast Friday by Al-Jazeera television...","label":"World"},{"text":"Storms leave at least 350 dead in Philippines The death toll from landslides and flash floods in the eastern Philippines jumped to nearly 350 with 150 others missing yesterday, most of them from a region still reeling from last week #39;s deadly typhoon.","label":"World"},{"text":"Buttiglione bows out to resolve EU crisis Rocco Buttiglione, the Italian nominee to the European Commission whose views on homosexuality resulted in an impasse with MEPs, yesterday decided to step aside.","label":"World"},{"text":"US air strikes hit Fallujah, locals claim family of six dead FALLUJAH, Iraq - US air raids destroyed two buildings said to belong to top militant Abu Mussab al-Zarqawi in the restive Iraqi city of Fallujah on Wednesday where residents claimed a family of six were killed.","label":"World"},{"text":"Leaders pay tribute to Arafat Yasser Arafats formal military funeral in Cairo was a sombre and dignified occasion.","label":"World"},{"text":"Peace returns to Najaf Amid the twisted metal and rubble of downtown storefronts and homes, in the side streets where residents tentatively ventured out, and even among the rebels in retreat, the word ","label":"World"},{"text":"Syria Urged to Pull Troops From Lebanon (AP) AP - A senior U.S. diplomat urged Syria's president Saturday to withdraw his country's troops from Lebanon and stop interfering in internal Lebanese affairs, a message delivered at a time when Syrian-American relations have been particularly strained.","label":"World"},{"text":"Policemen injured after fight 14/11/2004 A police inspector, two sergeants and two constables were hospitalised after being slightly injured when they went to investigate a fight in Paceville.","label":"World"},{"text":"US jets hit Fallujah ahead of expected offensive; residents report &lt;b&gt;...&lt;/b&gt; US jets pounded parts of Fallujah on Thursday, targeting insurgents in a city where American forces were said to be gearing up for a major offensive.","label":"World"},{"text":"Asian parties hope to deepen exchanges: Senior CPC official All Asian political parties share the hope of further deepening their exchanges and cooperation in the 21st century, said Liu Yunshan, a member of the Political Bureau of the CPC Central Committee on Sunday.","label":"World"},{"text":"Japan says yuan policy up to China ahead of G7 Japanese officials, arriving in Washington on Thursday for a historic meeting between the Group of Seven (G7) nations and China, distanced themselves from US demands for a review of China #39;s currency policy.","label":"World"},{"text":"Car Bomb Near U.S. Convoy in Ramadi Kills 2 Iraqis (Reuters) Reuters - A car bomb exploded near a U.S.\\convoy in the western city of Ramadi on Tuesday, killing two\\civilians and wounding at least four, witnesses said.","label":"World"},{"text":"Venezuelans Throng to Polls in Chavez Referendum CARACAS, Venezuela (Reuters) - Venezuelans crowded polling stations on Sunday to vote on whether to recall left-wing President Hugo Chavez or back his mandate to govern the world's No. 5 oil exporter for the next two years.","label":"World"},{"text":"Japan death toll from Meari rises to 19, 8 missing The death toll from a tropical storm buffeting Japan rose yesterday to 19 after searchers found more victims, including two men buried inside their homes beneath mud and debris that had barreled down a mountainside.","label":"World"},{"text":"White House: Islamic Agency Aids Terror (AP) AP - The Bush administration on Wednesday accused a Sudan-based relief organization and five of its officials of helping finance Osama bin Laden and other terrorists.","label":"World"},{"text":"World Leaders React to Bush Victory Russian President Vladimir Putin led world leaders #39; tributes to George W. Bush #39;s victory in the US presidential race, saying it meant Americans had not allowed themselves to be cowed by terrorists.","label":"World"},{"text":"Ukraine Speaker: Keep Poisoning Out of Campaign (Reuters) Reuters - Ukraine's influential parliament speaker\\called on Monday for a scandal over the poisoning of opposition\\leader Viktor Yushchenko to be kept out of the country's\\presidential election campaign.","label":"World"},{"text":"South Korean Court Rules Against Capital Relocation The Constitutional Court of South Korea delivered a major blow to President Roh Moo-hyun today by virtually scuttling his high-profile plan to relocate the national capital away from Seoul.","label":"World"},{"text":"Vote for Pakistan prime minister Pakistan's parliament is expected on Friday to vote for outgoing Finance Minister Shaukat Aziz as prime minister.","label":"World"},{"text":"Hamas Says to Boycott Palestinian Presidential Vote (Reuters) Reuters - The Palestinian Islamic militant faction\\Hamas will boycott a Jan. 9 presidential election for a\\successor to Yasser Arafat, a senior Hamas leader said on\\Wednesday.","label":"World"},{"text":"Somaliland warns Somalia's leader The breakaway republic of Somaliland says it will retaliate if Somalia's new president poses a threat to its border.","label":"World"},{"text":"Grenade Kills Two at Colombo Bollywood Concert COLOMBO (Reuters) - Two people were killed and 11 wounded when a hand grenade exploded in the VIP section of the audience at a concert led by Indian film superstar Shah Rukh Khan and two other actors, police said.","label":"World"},{"text":"France sends FM to free hostages in Iraq The French government sent its foreign minister Sunday to the Middle East region to try to free two French journalists held hostage in Iraq as a truce was reached in Baghdad #39;s slum of Sadr City.","label":"World"},{"text":"Israel diverts Lufthansa jet to Cyprus Israel has turned away a Lufthansa passenger plane bound for Tel Aviv due to a bomb threat. The plane landed safely in Cyprus on Tuesday after it was escorted by Israeli air force fighters.","label":"World"},{"text":"Palestinian PM threatens to quit PALESTINIAN prime minister Ahmed Qurie has again threatened to resign over differences with leader Yasser Arafat ahead of a meeting of donor countries who help fund the Palestinian Authority, officials said today.","label":"World"},{"text":"Syrian Troop Redeployment Said Meaningless Israeli Prime Minister Ariel Sharon reacted skeptically on Wednesday to a redeployment of Syrian troops in Lebanon, saying that the move did not mean any real change in Syrian policy.","label":"World"},{"text":"Finnish ski jumping ace heads for crash landing in life (AFP) AFP - The life of Matti Nykaenen, arguably the best ski jumper of all times, is primarily a tale of great sporting achievements, but also about ups and downs and then some more downs, as alcohol and violence ravage his existence.","label":"Sports"},{"text":"Astros Take on Cards, Red Sox Face Yanks NEW YORK - A day after giving Boston ace Curt Schilling a pounding, the New York Yankees look to take a 2-0 lead over Pedro Martinez and the Red Sox in Game 2 of the American League Championship Series on Wednesday night. Meanwhile, the National League Championship Series gets underway when the Houston Astros take on the St...","label":"Sports"},{"text":"Yankees Stun BoSox 19-8 for 3-0 ALCS Lead BOSTON - The Yankees kept circling the bases, battering Boston's beleaguered pitching staff. By the time the long, long night ended with a devastating 19-8 rout over the Red Sox, the dreaded New Yorkers were just one game away from a shocking sweep...","label":"Sports"},{"text":"Hain hit with eggs in hunt demo Commons leader Peter Hain is pelted with eggs and his aide punched during a pro-hunt demonstration in Oxford.","label":"Sports"},{"text":"Hits Record Is Ichiro's 'Best Moment' SEATTLE - The 258th hit in 2004 for Ichiro Suzuki was like so many others, a little ground ball up the middle. Only this one made history - a hit cheered 'round the world...","label":"Sports"},{"text":"Giants Walk to 6-5 Win Over Marlins Walking Barry Bonds intentionally to load the bases in the 10th inning turned out to be the wrong move for Florida - because Rudy Seanez then walked pinch-hitter A.J. Pierzynski on four pitches...","label":"Sports"},{"text":"Police called in to Old Trafford buffet battle (AFP) AFP - Manchester police have been asked give evidence into the Old Trafford buffet battle when an Arsenal player was alleged to have thrown soup and pizza at Manchester United manager Alex Ferguson.","label":"Sports"},{"text":"India boosted as Rathore grabs historic silver (Reuters) Reuters - India erupted with joy as shooter Rajyavardhan Rathore clinched their first medal at the Athens Olympics on Tuesday and their first ever individual silver.","label":"Sports"},{"text":"Burger mouthful goes for record SPURRED on by shouts of quot;shove it in, shove it in quot;, 19-year-old Don Ezra Nicholas stuffed more than three McDonald #39;s hamburgers into his mouth - without swallowing - and claimed a new global record at the close of Singapore #39;s contest to be the world #39;s ","label":"Sports"},{"text":"F1: Montoya sets early pace Juan Pablo Montoya tops the times in the opening practice session at Interlagos.","label":"Sports"},{"text":"Football: Man Utd beat Liverpool Mikael Silvestre's headed brace gives Man Utd victory over Liverpool on Rio Ferdinand's return to first-team action.","label":"Sports"},{"text":"Giants Beat Astros to Keep Wild Card Lead Barry Bonds and the San Francisco Giants can reach the playoffs two ways. They certainly boosted both chances Tuesday night...","label":"Sports"},{"text":"Players Union Challenges Carter's Release The NFL Players Association has gotten involved in Quincy Carter's release by the Dallas Cowboys. The union filed a grievance over the release Aug...","label":"Sports"},{"text":"Red Sox Beat Yankees 6-4 in 12 Innings BOSTON - Down to their last three outs of the season, the Boston Red Sox rallied - against Mariano Rivera, the New York Yankees and decades of disappointment. Bill Mueller singled home the tying run off Rivera in the ninth inning and David Ortiz homered against Paul Quantrill in the 12th, leading Boston to a 6-4 victory Sunday over the Yankees that avoided a four-game sweep in the AL championship series...","label":"Sports"},{"text":"China sports star in Aids campaign Aids activists get help from Chinese basketball star Yao Ming, back in Shanghai for a promotional game.","label":"Sports"},{"text":"Golf: Woods' swing blamed for dip Vijay Singh says Tiger Woods lost his number one status after failing to change his swing.","label":"Sports"},{"text":"Manny #39;s chance at life with two dads CAUGHT at the centre of a tug-of-love, Manny Musu could have a future with two dads, her Australian father said yesterday. Sydney policeman Dave Norman has been trying ","label":"Sports"},{"text":"Boxing: Williams to face Klitschko Danny Williams will take on WBC world heavyweight champion Vitali Klitschko in December.","label":"Sports"},{"text":"Barrichello Fires Up the Fans in Brazil &lt;p&gt;&lt;/p&gt;&lt;p&gt; By Alan Baldwin&lt;/p&gt;&lt;p&gt; SAO PAULO (Reuters) - Ferrari's Rubens Barrichello fired uphis passionate home crowd on Friday with the fastest lap inpractice for Sunday's season-ending Brazilian Grand Prix.&lt;/p&gt;","label":"Sports"},{"text":"Bush Bikes Ahead of Christmas Celebration (AP) AP - President Bush attended church and went mountain biking Sunday before heading to a Christmas celebration.","label":"Sports"},{"text":"VOICE MAIL Your brilliant lead article entitled #39;Of The Bullet, for the bullet, by the bullet #39; clearly sums up the whole truth about the Veerappan drama.","label":"Sports"},{"text":"Football: Nine-man Arsenal draw Lauren and Patrick Vieira are sent off as Arsenal draw against PSV Eindhoven in the Champions League.","label":"Sports"},{"text":"Cricket: ICC trophy preview The Champions Trophy final against West Indies is England's biggest one-day match for 12 years.","label":"Sports"},{"text":"Football: Juve doctor convicted A doctor is convicted of administering banned drugs to Juventus players in the 1990s.","label":"Sports"},{"text":"Cricket: Pressure mounts on NZ Glenn McGrath's maiden Test fifty takes Australia to 564-9 against New Zealand, ahead by 211 runs.","label":"Sports"},{"text":"Surfer #39;torn to pieces #39; by shark Authorities in Sydney said today they would kill the shark that tore apart a young surfer near a popular beach as his friends desperately tried to save him by beating the animal with oars.","label":"Sports"},{"text":"Singh Knocks Woods From Top Spot in Golf NORTON, Mass. - Vijay Singh has been playing the best golf in the world for a long time...","label":"Sports"},{"text":"Jury Selection Begins in Kobe Bryant Case EAGLE, Colo. - After 14 months of sordid headlines and days of hearings that left unanswered questions, Kobe Bryant's sexual assault trial was to begin with hundreds of people scheduled to arrive for the first wave of jury selection...","label":"Sports"},{"text":"Yanks Go Up 2-0; Cardinals Win Opener NEW YORK - Jon Lieber took a shutout into the eighth inning and John Olerud backed him with a two-run homer in the sixth off Pedro Martinez as the Yankees beat the Red Sox 3-1 Wednesday night for a 2-0 lead in their AL championship series rematch. In the National League series opener Wednesday night, Albert Pujols homered early, Larry Walker delivered three key hits and the St...","label":"Sports"},{"text":"Orioles Drub Streaking Yankees 14-8 BALTIMORE - Brian Roberts and Larry Bigbie had two hits apiece in an eight-run third inning, and the Baltimore Orioles ended the New York Yankees' five-game winning streak with a 14-8 victory Friday night. Miguel Tejada and Melvin Mora homered, and B.J...","label":"Sports"},{"text":"No rthern Trust Bank of Florida has full Major League Baseball player Rick Helling, right, talks with an unidentified Player #39;s Association representative as he arrives to attend meetings Monday, Dec. 6, 2004, at the Royal Palms Resort in Phoenix.","label":"Sports"},{"text":"Puerto Rico Stuns Dream Team, 92-73 ATHENS, Greece - In an upset as historic as it was inevitable, Tim Duncan, Allen Iverson and the rest of the U.S. basketball team lost 92-73 to Puerto Rico on Sunday, only the third Olympic loss ever for America and its first since adding pros...","label":"Sports"},{"text":"Fleming 'alarmed' by Aussies' thorough planning (AFP) AFP - New Zealand skipper Stephen Fleming said he was alarmed at the scale of planning Australia had put in to conquer their final cricket frontier in India.","label":"Sports"},{"text":"Murali upset over awards Muttiah Muralitharan says he was ignored for the ICC's World Test XI because of his bowling action.","label":"Sports"},{"text":"Hunt supporters storm British parliament, but ban moves closer (AFP) AFP - Supporters of fox hunting stormed Britain's parliament and scuffled with police at a mass rally, but failed to prevent lawmakers from moving closer to a ban of the blood sport.","label":"Sports"},{"text":"Jackson bid to remove prosecutor Lawyers acting for Michael Jackson in the child molestation case bid to have prosecutor removed.","label":"Sports"},{"text":"Attorney Says Heels May Hurt Sobriety Test DURHAM, N.C. - Attorney Bill Thomas may get a lot more business from female motorists thanks to a novel defense strategy: High heels can help beat a DWI rap...","label":"Sports"},{"text":"Padres Blank Dodgers 3-0 LOS ANGELES - Adam Eaton allowed five hits over seven innings for his career-high 10th victory, Brian Giles homered for the second straight game, and the San Diego Padres beat the Los Angeles Dodgers 3-0 Thursday night. The NL West-leading Dodgers' lead was cut to 2 1/2 games over San Francisco - their smallest since July 31...","label":"Sports"},{"text":"Golf: Record earnings for Singh Vijay Singh leads from start to finish to win the 84 Lumber Classic and eclipse Tiger Woods' season earnings record.","label":"Sports"},{"text":"Football: England v Poland Sven-Goran Eriksson may gamble by playing goalkeeper Paul Robinson and striker Jermain Defoe in Poland.","label":"Sports"},{"text":"No. 13 Louisville 85, N. Carolina A amp;T 51 Larry O #39;Bannon scored a season-high 25 points and grabbed 11 rebounds to lead No. 13 Louisville to an 85-51 victory over North Carolina A amp;T on Tuesday night.","label":"Sports"},{"text":"Vaughan and Jones to fore in another mismatch THE sight of Andrew Strauss delivering the penultimate over of this mismatch said more about the state of Zimbabwe cricket than any number of words.","label":"Sports"},{"text":"Old Lady running well, Inter Milan held back by X syndrome The Turin powerhouse, nicknamed quot;Vecchia Signora quot; by its fans, enters Sunday #39;s 12th round of Serie A with an impressive 9-1-1 record and a six-point lead over second-place AC Milan, the defending champion.","label":"Sports"},{"text":"Bryan twins put US in Davis Cup final Charleston, SC (Sports Network) - Bob and Mike Bryan teamed-up for a doubles win over Belarus on Saturday to clinch a spot in the Davis Cup final for the United States for the first time in seven years.","label":"Sports"},{"text":"Parma Sack Baldini Silvio Baldinis adventure at Parma is over as on Monday morning the Ducali announced his sacking. This was partly due to their latest defeat at Livorno which leaves the Gialloblu firmly anchored in the last places of Serie A.","label":"Sports"},{"text":"Chiefs Overtake Titans in Wild Finish A phantom penalty, followed by a 9-yard touchdown catch by Eddie Kennison, lifted the Kansas City Chiefs past the undermanned Tennessee Titans, 49-38.","label":"Sports"},{"text":"Getting Greene #39;s GOAT a chore worthy of an Olympic medal The tattoo on Maurice Greene #39;s right shoulder succinctly sums up where he feels he ranks in the world of sprinting. quot;Greatest of all time, quot; he will shout after a victory while thumping it.","label":"Sports"},{"text":"Source: Bears Intend to Sign QB George (AP) AP - Struggling desperately at quarterback, the Chicago Bears intend to sign veteran Jeff George, a team source said Saturday night.","label":"Sports"},{"text":"Ravens' Lewis, Smith Injured Vs. Cowboys (AP) AP - Baltimore Ravens running back Jamal Lewis hurt his left ankle in the first quarter Sunday, and backup Musa Smith broke his leg later in the period.","label":"Sports"},{"text":"Greece brought back to earth Greece, whose European Championship triumph stunned football only two months ago, suffered a rapid fall from grace when they were beaten by Albania in their opening qualifier for the 2006 World Cup.","label":"Sports"},{"text":"Green Groups Praise Russian Decision to Ratify Kyoto Major international environmental groups have hailed the decision by the government of Russian President Vladimir Putin to endorse ratification of the 1997 Kyoto Protocol as a historic breakthrough in curbing global warming.","label":"Sci/Tech"},{"text":"Bush Seeks to Build on His Education Base (AP) AP - President Bush is ready to shift his education focus to older students, building on the law he pushed through before terrorism and war came to define his presidency.","label":"Sci/Tech"},{"text":"Iran's Bushehr Atomic Power Plant Faces More Delays TEHRAN (Reuters) - Iran on Sunday announced a further substantial delay in the long overdue project to complete its first nuclear power plant, part of a program which Washington says could be used to make atomic arms.","label":"Sci/Tech"},{"text":"India Test Fires Nuclear-Capable Missile India successfully test fired a long-range nuclear-capable Agni II missile off its eastern coast of Orissa Sunday, a defense ministry spokesman said.","label":"Sci/Tech"},{"text":"Indo-Pak officials begin talks on nuclear CBMs, Sir Creek Islamabad: India and Pakistan on Tuesday began separate talks here on nuclear confidence building measures and to work out modalities to conduct joint survey of pillars at Sir Creek area of the Gujarat coast.","label":"Sci/Tech"},{"text":"UN Experts Visit Brazil Nuclear Facility (Reuters) Reuters - U.N. nuclear experts visited\\Brazil's new uranium enrichment plant on Tuesday to try to\\break an impasse over nonproliferation inspections, although\\how much they would be allowed to see remained at issue.","label":"Sci/Tech"},{"text":"Russia to ratify Kyoto treaty Politicians, industry leaders and environment groups across the world welcomed the news last night that Russia had rejuvenated international efforts to combat climate change by ratifying the Kyoto protocol.","label":"Sci/Tech"},{"text":"India Launches First Education Satellite India #39;s space agency said it successfully launched the nation #39;s first satellite for educational services on Monday, which is expected to boost distance learning in a country with a huge rural population.","label":"Sci/Tech"},{"text":"Japan, ASEAN to outline antiterrorism cooperation Top leaders of Japan and the Association of Southeast Asian Nations (ASEAN) are set to adopt a statement next week in Laos outlining antiterrorism cooperation among their police forces, according to Japanese Foreign Ministry.","label":"Sci/Tech"},{"text":"An 'electronic eye' for the blind Japanese scientists have built an electronic eye they say could help blind people get around safely.","label":"Sci/Tech"},{"text":"Stationmasters Face Charges in India Crash Railway officials say a train collision in northern India that killed at least 37 people apparently was caused by a communications lapse between stations, and that the two stationmasters face criminal charges in the disaster.","label":"Sci/Tech"},{"text":"Iran abandons centrifuge demands Iran has abandoned its demand to be allowed to continue some of its controversial nuclear activities, the BBC reported Sunday. UN nuclear watchdog International Atomic Energy ","label":"Sci/Tech"},{"text":"High Court Orders Review of Texas Seats (AP) AP - The Supreme Court on Monday ordered a lower court to reconsider a Texas congressional map that could give Republicans six more seats in Congress in upcoming elections and help the GOP protect its majority.","label":"Sci/Tech"},{"text":"Iran suspending uranium enrichment TEHRAN, Iran - Iran said Monday that it was suspending uranium enrichment and related activities briefly, voluntarily and in hopes of building confidence in the world that its nuclear ambitions are peaceful.","label":"Sci/Tech"},{"text":"U.N. Tells Iran to Suspend Nuke Program VIENNA, Austria - The U.N. atomic watchdog agency demanded Iran suspend all uranium enrichment activities and set a November timetable for compliance in a vote Saturday that U.S...","label":"Sci/Tech"},{"text":"U.S. Nuclear Shipment En Route to France (Reuters) Reuters - A controversial U.S. shipment of\\bomb-grade plutonium escorted by armed British commandos has\\set sail for France, despite protests from environmental\\activists who fear a terrorist attack or an accident.","label":"Sci/Tech"},{"text":"Appeals Court Denies Moussaoui Hearing WASHINGTON - Terrorism suspect Zacarias Moussaoui lost a bid Wednesday to have the full 4th U.S. Circuit Court of Appeals review two issues - witness access and the death penalty - that have delayed a trial...","label":"Sci/Tech"},{"text":"Swiss voters approve stem cell research using human embryos GENEVA (AFP) - Two-thirds of Swiss voters approved a new law that allows medical research on stem cells taken from human embryos but bars cloning, official results from a referendum showed.","label":"Sci/Tech"},{"text":"UN agency gives Iran a reprieve Iran today received the qualified backing of the UN #39;s nuclear watchdog just 10 days short of a deadline to address US and European concerns over its programmes.","label":"Sci/Tech"},{"text":"Gene clue to malaria drug failure A gene could explain how parasites which cause malaria escape the action of some antimalaria drugs, say researchers.","label":"Sci/Tech"},{"text":"AP: Iran Moves Toward Nuclear Production TEHRAN, Iran - Iran has produced \"a few tons\" of the gas needed to enrich uranium, a top nuclear official said Wednesday, confirming the country has defied international demands and taken a necessary step toward producing nuclear fuel - or nuclear weapons. Uranium hexafluoride gas is the material that, in the next stage, is fed into centrifuges used to enrich uranium...","label":"Sci/Tech"},{"text":"India test-fires nuclear-capable ballistic missile (AFP) AFP - India has successfully tested a naval version of its Prithvi-III nuclear-capable medium range ballistic missile, defence sources say.","label":"Sci/Tech"},{"text":"Nuclear ship docks in French port The first of two ships carrying weapons-grade plutonium from the United States has docked in France. The British-registered Pacific Pintail is said to be carrying enough plutonium to make 40 nuclear bombs.","label":"Sci/Tech"},{"text":"Alaskans to Vote on Legalizing Marijuana (Reuters) Reuters - Voters in Alaska will decide on\\Tuesday whether to make their state the first in the country to\\legalize the sale, possession or use of marijuana by adults.","label":"Sci/Tech"},{"text":"You #39;ll be back, Arnie tells Japan HE was last in Japan as the Terminator, while he was away he became the Governator, and now he #39;s back as ... what, the Promotivator?","label":"Sci/Tech"},{"text":"Mexican State Recruits Cats to Fight Rats MONTERREY, Mexico - Health authorities in the northern state of Chihuahua said Tuesday they are recruiting hundreds of cats to fight hundreds of thousands of rats. Chihuahua state officials say they hope to collect as many as 700 felines and send them to Atascaderos, an isolated farm village in the rugged Tarahumara mountains, a region where officials estimate there are about a half million rats...","label":"Sci/Tech"},{"text":"Astronomers Spot Smallest Planets Yet American astronomers say they have discovered the two smallest planets yet orbiting nearby stars, trumping a small planet discovery by European scientists five days ago and capping the latest round in a frenzied hunt for other worlds like Earth. All three of these smaller planets belong to a new class of \"exoplanets\" - those that orbit stars other than our sun, the scientists said in a briefing Tuesday...","label":"Sci/Tech"},{"text":"Watch Lists Glance (AP) AP - Other measures related to transportation security, besides expanded use of government watch lists on flights, cruises and at airports, included in the intelligence overhaul legislation:","label":"Sci/Tech"},{"text":"ElBaradei Says Unclear if Iran Nuke Plans Peaceful VIENNA (Reuters) - It is unclear if Iran's nuclear ambitions are entirely peaceful, but there is still no firm evidence that Tehran is secretly developing atomic weapons as Washington asserts, the U.N. nuclear watchdog said on Tuesday.","label":"Sci/Tech"},{"text":"Russian move clears way to bring Kyoto into force The Russian government approved the Kyoto Protocol on Thursday, giving decisive support to the long-delayed climate change treaty that should allow it to come into force worldwide.","label":"Sci/Tech"},{"text":"Study Shows Dogs Able to Smell Cancer LONDON - It has long been suspected that man's best friend has a special ability to sense when something is wrong with us. Now the first experiment to verify that scientifically has demonstrated that dogs are able to smell cancer...","label":"Sci/Tech"},{"text":"Analyst: U.S. Weapons Tests in Australia (AP) AP - American troops will train with new U.S. military equipment in Australia under a pact being negotiated by Washington and Canberra, a prominent defense analyst said Friday.","label":"Sci/Tech"},{"text":"Congress Ends Deadlock on Intel Overhaul (AP) AP - Breaking a monthslong deadlock, key congressional negotiators reported agreement Saturday on legislation to overhaul the nation's intelligence agencies along lines recommended by the Sept. 11 commission.","label":"Sci/Tech"},{"text":"Mullah: Iran bids to join nuclear tech club Mullah Rafsanjani said here Friday that Tehran expects it would become a member of the club of countries possessing nuclear technology.","label":"Sci/Tech"},{"text":"Russia announces work on unique nuclear missile system MOSCOW -- Russia is developing a new nuclear missile system unlike any weapon held by other countries, President Vladimir Putin announced yesterday, in a move that could serve as a message to the United States as Washington pushes forward with a missile defense system.","label":"Sci/Tech"},{"text":"French president inaugurates world #39;s tallest bridge French President Jacques Chirac inaugurated Tuesday the world #39;s tallest bridge, the viaductof Millau of 270 meters above ground.","label":"Sci/Tech"},{"text":"Japan, US sign missile defense cooperation memo Japan and the United States signed an agreement Friday on the details of their joint development of a ballistic missile defense system.","label":"Sci/Tech"},{"text":"Gamer buys \\$26,500 virtual land An Australian gamer spends \\$26,500 on a virtual island that exists only in a PC role-playing game.","label":"Sci/Tech"},{"text":"Pak test fires medium range missile #39;Hataf-V #39; Islamabad, Oct 12 (PTI) Pakistan today quot;successfully quot; carried out yet another test of its intermediate range ballistic missile #39;Hataf-V #39;, with a strike range of 1500 km capable of carrying nuclear and conventional warheads and targetting most of the ","label":"Sci/Tech"},{"text":"Emissions double heatwave risk Greenhouse gas emissions have doubled the risk of European heatwaves similar to last year's, a UK study says.","label":"Sci/Tech"},{"text":"Malaysian bird flu an isolated case A recent case of bird flu Malaysia appears to be an isolated event, the World Health Organization says. Health officials have confirmed the case, found in the poultry of ","label":"Sci/Tech"},{"text":"Court Throws Out Texas Death Sentence (AP) AP - The Supreme Court on Monday overturned the death sentence of a convicted Texas killer because jurors in his trial did not consider his learning disability and other evidence.","label":"Sci/Tech"},{"text":"\\$591m boost to embassy security THE Federal Government will spend \\$591 million on boosting security at Australian missions overseas, providing better protection for staff and visitors.","label":"Sci/Tech"},{"text":"WTO Negotiators Finish Week of Farm Talks Negotiators at the World Trade Organization completed weeklong farm talks Friday, part of discussions on ways to reach a wider-ranging liberalization accord by the end of 2005.","label":"Sci/Tech"},{"text":"Reconsider highway project I am a professor of geography visiting Taiwan, and have read about the proposed construction of a freeway from Taipei to Hualien. The experience of communities in North America and Europe has been fairly consistent ","label":"Sci/Tech"},{"text":"Putin Ratifies Kyoto Protocol on Emissions President Vladimir V. Putin on Friday signed Russia #39;s ratification of the Kyoto Protocol on global warming, the Kremlin announced, clearing the way for the international ","label":"Sci/Tech"},{"text":"No deadline for Iran investigation: IAEA VIENNA: United Nations (UN) nuclear chief Mohamed ElBaradei said on Monday that there was no deadline for ending an investigation into Irans nuclear programme, even though Iran said it expects the investigation to wrap up in November.","label":"Sci/Tech"},{"text":"Former private school teacher to face criminal charges in court Wednesday (Canadian Press) Canadian Press - TORONTO (CP) - A former Upper Canada College teacher made a brief court appearance Monday to face sexual assault charges.","label":"Sci/Tech"},{"text":"Waistline linked to health risks Scientists believe measuring your waist could be a better indicator of future health than weighing yourself.","label":"Sci/Tech"},{"text":"House Blocks Court on Pledge Case Rulings (AP) AP - The House, in an emotionally and politically charged debate six weeks before the election, voted Thursday to protect the words \"under God\" in the Pledge of Allegiance from further court challenges.","label":"Sci/Tech"}]; const SMS_SAMPLE = [{"text":"Yeah he got in at 2 and was v apologetic. n had fallen out and she was actin like spoilt child and he got caught up in that. Till 2! But we won't go there! Not doing too badly cheers. You?","label":"ham"},{"text":"I HAVE A DATE ON SUNDAY WITH WILL!!","label":"ham"},{"text":"Fine if that’s the way u feel. That’s the way its gota b","label":"ham"},{"text":"I've been searching for the right words to thank you for this breather. I promise i wont take your help for granted and will fulfil my promise. You have been wonderful and a blessing at all times.","label":"ham"},{"text":"Your gonna have to pick up a $1 burger for yourself on your way home. I can't even move. Pain is killing me.","label":"ham"},{"text":"I‘m going to try for 2 months ha ha only joking","label":"ham"},{"text":"Ok lar... Joking wif u oni...","label":"ham"},{"text":"Ringtone Club: Get the UK singles chart on your mobile each week and choose any top quality ringtone! This message is free of charge.","label":"spam"},{"text":"SMS. ac Blind Date 4U!: Rodds1 is 21/m from Aberdeen, United Kingdom. Check Him out http://img. sms. ac/W/icmb3cktz8r7!-4 no Blind Dates send HIDE","label":"spam"},{"text":"SIX chances to win CASH! From 100 to 20,000 pounds txt> CSH11 and send to 87575. Cost 150p/day, 6days, 16+ TsandCs apply Reply HL 4 info","label":"spam"},{"text":"Ffffffffff. Alright no way I can meet up with you sooner?","label":"ham"},{"text":"Urgent UR awarded a complimentary trip to EuroDisinc Trav, Aco&Entry41 Or £1000. To claim txt DIS to 87121 18+6*£1.50(moreFrmMob. ShrAcomOrSglSuplt)10, LS1 3AJ","label":"spam"},{"text":"WINNER!! As a valued network customer you have been selected to receivea £900 prize reward! To claim call 09061701461. Claim code KL341. Valid 12 hours only.","label":"spam"},{"text":"A gram usually runs like &lt;#&gt; , a half eighth is smarter though and gets you almost a whole second gram for &lt;#&gt;","label":"ham"},{"text":"URGENT! We are trying to contact you. Last weekends draw shows that you have won a £900 prize GUARANTEED. Call 09061701939. Claim code S89. Valid 12hrs only","label":"spam"},{"text":"U dun say so early hor... U c already then say...","label":"ham"},{"text":"Yes..gauti and sehwag out of odi series.","label":"ham"},{"text":"Congratulations ur awarded 500 of CD vouchers or 125gift guaranteed & Free entry 2 100 wkly draw txt MUSIC to 87066 TnCs www.Ldew.com1win150ppmx3age16","label":"spam"},{"text":"-PLS STOP bootydelious (32/F) is inviting you to be her friend. Reply YES-434 or NO-434 See her: www.SMS.ac/u/bootydelious STOP? Send STOP FRND to 62468","label":"spam"},{"text":"Your free ringtone is waiting to be collected. Simply text the password \"MIX\" to 85069 to verify. Get Usher and Britney. FML, PO Box 5249, MK17 92H. 450Ppw 16","label":"spam"},{"text":"Did you catch the bus ? Are you frying an egg ? Did you make a tea? Are you eating your mom's left over dinner ? Do you feel my Love ?","label":"ham"},{"text":"I'm gonna be home soon and i don't want to talk about this stuff anymore tonight, k? I've cried enough today.","label":"ham"},{"text":"K tell me anything about you.","label":"ham"},{"text":"Eh u remember how 2 spell his name... Yes i did. He v naughty make until i v wet.","label":"ham"},{"text":"07732584351 - Rodger Burns - MSG = We tried to call you re your reply to our sms for a free nokia mobile + free camcorder. Please call now 08000930705 for delivery tomorrow","label":"spam"},{"text":"Hello! How's you and how did saturday go? I was just texting to see if you'd decided to do anything tomo. Not that i'm trying to invite myself or anything!","label":"ham"},{"text":"Wait that's still not all that clear, were you not sure about me being sarcastic or that that's why x doesn't want to live with us","label":"ham"},{"text":"Anything lor... U decide...","label":"ham"},{"text":"500 New Mobiles from 2004, MUST GO! Txt: NOKIA to No: 89545 & collect yours today!From ONLY £1 www.4-tc.biz 2optout 087187262701.50gbp/mtmsg18","label":"spam"},{"text":"Fair enough, anything going on?","label":"ham"},{"text":"T-Mobile customer you may now claim your FREE CAMERA PHONE upgrade & a pay & go sim card for your loyalty. Call on 0845 021 3680.Offer ends 28thFeb.T&C's apply","label":"spam"},{"text":"Please call our customer service representative on FREEPHONE 0808 145 4742 between 9am-11pm as you have WON a guaranteed £1000 cash or £5000 prize!","label":"spam"},{"text":"Wow. I never realized that you were so embarassed by your accomodations. I thought you liked it, since i was doing the best i could and you always seemed so happy about \"the cave\". I'm sorry I didn't and don't have more to give. I'm sorry i offered. I'm sorry your room was so embarassing.","label":"ham"},{"text":"Valentines Day Special! Win over £1000 in our quiz and take your partner on the trip of a lifetime! Send GO to 83600 now. 150p/msg rcvd. CustCare:08718720201.","label":"spam"},{"text":"U 447801259231 have a secret admirer who is looking 2 make contact with U-find out who they R*reveal who thinks UR so special-call on 09058094597","label":"spam"},{"text":"I see the letter B on my car","label":"ham"},{"text":"Great! I hope you like your man well endowed. I am &lt;#&gt; inches...","label":"ham"},{"text":"We tried to contact you re your reply to our offer of a Video Handset? 750 anytime networks mins? UNLIMITED TEXT? Camcorder? Reply or call 08000930705 NOW","label":"spam"},{"text":"Do you know what Mallika Sherawat did yesterday? Find out now @ &lt;URL&gt;","label":"ham"},{"text":"So ü pay first lar... Then when is da stock comin...","label":"ham"},{"text":"Will u meet ur dream partner soon? Is ur career off 2 a flyng start? 2 find out free, txt HORO followed by ur star sign, e. g. HORO ARIES","label":"spam"},{"text":"URGENT! Your Mobile No. was awarded £2000 Bonus Caller Prize on 5/9/03 This is our final try to contact U! Call from Landline 09064019788 BOX42WR29C, 150PPM","label":"spam"},{"text":"Even my brother is not like to speak with me. They treat me like aids patent.","label":"ham"},{"text":"I'm back &amp; we're packing the car now, I'll let you know if there's room","label":"ham"},{"text":"Aft i finish my lunch then i go str down lor. Ard 3 smth lor. U finish ur lunch already?","label":"ham"},{"text":"Ahhh. Work. I vaguely remember that! What does it feel like? Lol","label":"ham"},{"text":"Pls go ahead with watts. I just wanted to be sure. Do have a great weekend. Abiola","label":"ham"},{"text":"Customer service annoncement. You have a New Years delivery waiting for you. Please call 07046744435 now to arrange delivery","label":"spam"},{"text":"England v Macedonia - dont miss the goals/team news. Txt ur national team to 87077 eg ENGLAND to 87077 Try:WALES, SCOTLAND 4txt/ú1.20 POBOXox36504W45WQ 16+","label":"spam"},{"text":"GENT! We are trying to contact you. Last weekends draw shows that you won a £1000 prize GUARANTEED. Call 09064012160. Claim Code K52. Valid 12hrs only. 150ppm","label":"spam"},{"text":"Want 2 get laid tonight? Want real Dogging locations sent direct 2 ur mob? Join the UK's largest Dogging Network bt Txting GRAVEL to 69888! Nt. ec2a. 31p.msg@150p","label":"spam"},{"text":"Free entry in 2 a wkly comp to win FA Cup final tkts 21st May 2005. Text FA to 87121 to receive entry question(std txt rate)T&C's apply 08452810075over18's","label":"spam"},{"text":"PRIVATE! Your 2004 Account Statement for 07742676969 shows 786 unredeemed Bonus Points. To claim call 08719180248 Identifier Code: 45239 Expires","label":"spam"},{"text":"For fear of fainting with the of all that housework you just did? Quick have a cuppa","label":"ham"},{"text":"Call Germany for only 1 pence per minute! Call from a fixed line via access number 0844 861 85 85. No prepayment. Direct access!","label":"spam"},{"text":"Tell where you reached","label":"ham"},{"text":"Think ur smart ? Win £200 this week in our weekly quiz, text PLAY to 85222 now!T&Cs WinnersClub PO BOX 84, M26 3UZ. 16+. GBP1.50/week","label":"spam"},{"text":"Go until jurong point, crazy.. Available only in bugis n great world la e buffet... Cine there got amore wat...","label":"ham"},{"text":"Sunshine Quiz Wkly Q! Win a top Sony DVD player if u know which country the Algarve is in? Txt ansr to 82277. £1.50 SP:Tyrone","label":"spam"},{"text":"No calls..messages..missed calls","label":"ham"},{"text":"Thanks for your subscription to Ringtone UK your mobile will be charged £5/month Please confirm by replying YES or NO. If you reply NO you will not be charged","label":"spam"},{"text":"HMV BONUS SPECIAL 500 pounds of genuine HMV vouchers to be won. Just answer 4 easy questions. Play Now! Send HMV to 86688 More info:www.100percent-real.com","label":"spam"},{"text":"Nah I don't think he goes to usf, he lives around here though","label":"ham"},{"text":"TheMob> Check out our newest selection of content, Games, Tones, Gossip, babes and sport, Keep your mobile fit and funky text WAP to 82468","label":"spam"},{"text":"XXXMobileMovieClub: To use your credit, click the WAP link in the next txt message or click here>> http://wap. xxxmobilemovieclub.com?n=QJKGIGHJJGCBL","label":"spam"},{"text":"Ur ringtone service has changed! 25 Free credits! Go to club4mobiles.com to choose content now! Stop? txt CLUB STOP to 87070. 150p/wk Club4 PO Box1146 MK45 2WT","label":"spam"},{"text":"Yup... Ok i go home look at the timings then i msg ü again... Xuhui going to learn on 2nd may too but her lesson is at 8am","label":"ham"},{"text":"What you thinked about me. First time you saw me in class.","label":"ham"},{"text":"URGENT! You have won a 1 week FREE membership in our £100,000 Prize Jackpot! Txt the word: CLAIM to No: 81010 T&C www.dbuk.net LCCLTD POBOX 4403LDNW1A7RW18","label":"spam"},{"text":"Hey I am really horny want to chat or see me naked text hot to 69698 text charged at 150pm to unsubscribe text stop 69698","label":"spam"},{"text":"FreeMsg Why haven't you replied to my text? I'm Randy, sexy, female and live local. Luv to hear from u. Netcollex Ltd 08700621170150p per msg reply Stop to end","label":"spam"},{"text":"Todays Voda numbers ending 7548 are selected to receive a $350 award. If you have a match please call 08712300220 quoting claim code 4041 standard rates app","label":"spam"},{"text":"SMS. ac Sptv: The New Jersey Devils and the Detroit Red Wings play Ice Hockey. Correct or Incorrect? End? Reply END SPTV","label":"spam"},{"text":"K fyi x has a ride early tomorrow morning but he's crashing at our place tonight","label":"ham"},{"text":"Oh k...i'm watching here:)","label":"ham"},{"text":"Are you unique enough? Find out from 30th August. www.areyouunique.co.uk","label":"spam"},{"text":"U don't know how stubborn I am. I didn't even want to go to the hospital. I kept telling Mark I'm not a weak sucker. Hospitals are for weak suckers.","label":"ham"},{"text":"Lol your always so convincing.","label":"ham"},{"text":"You are a winner U have been specially selected 2 receive £1000 cash or a 4* holiday (flights inc) speak to a live operator 2 claim 0871277810810","label":"spam"},{"text":"You are a winner U have been specially selected 2 receive £1000 or a 4* holiday (flights inc) speak to a live operator 2 claim 0871277810910p/min (18+)","label":"spam"},{"text":"Did I forget to tell you ? I want you , I need you, I crave you ... But most of all ... I love you my sweet Arabian steed ... Mmmmmm ... Yummy","label":"ham"},{"text":"BangBabes Ur order is on the way. U SHOULD receive a Service Msg 2 download UR content. If U do not, GoTo wap. bangb. tv on UR mobile internet/service menu","label":"spam"},{"text":"Is that seriously how you spell his name?","label":"ham"},{"text":"Text & meet someone sexy today. U can find a date or even flirt its up to U. Join 4 just 10p. REPLY with NAME & AGE eg Sam 25. 18 -msg recd@thirtyeight pence","label":"spam"},{"text":"Didn't you get hep b immunisation in nigeria.","label":"ham"},{"text":"Just forced myself to eat a slice. I'm really not hungry tho. This sucks. Mark is getting worried. He knows I'm sick when I turn down pizza. Lol","label":"ham"},{"text":"Did you hear about the new \"Divorce Barbie\"? It comes with all of Ken's stuff!","label":"spam"},{"text":"Oops, I'll let you know when my roommate's done","label":"ham"},{"text":"You'll not rcv any more msgs from the chat svc. For FREE Hardcore services text GO to: 69988 If u get nothing u must Age Verify with yr network & try again","label":"spam"},{"text":"Sorry, I'll call later in meeting.","label":"ham"},{"text":"Congrats! 1 year special cinema pass for 2 is yours. call 09061209465 now! C Suprman V, Matrix3, StarWars3, etc all 4 FREE! bx420-ip4-5we. 150pm. Dont miss out!","label":"spam"},{"text":"Yeah hopefully, if tyler can't do it I could maybe ask around a bit","label":"ham"},{"text":"FreeMsg Hey there darling it's been 3 week's now and no word back! I'd like some fun you up for it still? Tb ok! XxX std chgs to send, £1.50 to rcv","label":"spam"},{"text":"As a valued customer, I am pleased to advise you that following recent review of your Mob No. you are awarded with a £1500 Bonus Prize, call 09066364589","label":"spam"},{"text":"Please call our customer service representative on 0800 169 6031 between 10am-9pm as you have WON a guaranteed £1000 cash or £5000 prize!","label":"spam"},{"text":"WHO ARE YOU SEEING?","label":"ham"},{"text":"As per your request 'Melle Melle (Oru Minnaminunginte Nurungu Vettam)' has been set as your callertune for all Callers. Press *9 to copy your friends Callertune","label":"ham"},{"text":"Had your mobile 11 months or more? U R entitled to Update to the latest colour mobiles with camera for Free! Call The Mobile Update Co FREE on 08002986030","label":"spam"},{"text":"December only! Had your mobile 11mths+? You are entitled to update to the latest colour camera mobile for Free! Call The Mobile Update Co FREE on 08002986906","label":"spam"},{"text":"Ha ha ha good joke. Girls are situation seekers.","label":"ham"}]; let state = { rows: [], split: null, model: null, modelRows: [], labels: [], acc: null, report: null, cv: null }; function esc(s) { return String(s).replace(/[&<>"']/g, c => ({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[c])); } function splitCSV(line, delim) { const out = []; let cur = "", q = false; for (let i = 0; i < line.length; i++) { const c = line[i]; if (c === '"') { if (q && line[i + 1] === '"') { cur += '"'; i++; } else q = !q; } else if (c === delim && !q) { out.push(cur); cur = ""; } else cur += c; } out.push(cur); return out; } function parseData(text) { text = text.trim(); if (!text) throw new Error("no data"); if (text[0] === "[") { const arr = JSON.parse(text); return arr.map(r => ({ text: String(r.text || r.sentence || ""), label: String(r.label || r.class || "") })) .filter(r => r.text && r.label); } if (text[0] === "{") { return text.split(/\r?\n/).filter(Boolean).map(line => { const r = JSON.parse(line); return { text: String(r.text || r.sentence || ""), label: String(r.label || r.class || "") }; }).filter(r => r.text && r.label); } const lines = text.split(/\r?\n/).filter(l => l.trim()); const delim = lines[0].includes("\t") ? "\t" : ","; const rows = []; for (const line of lines) { const parts = splitCSV(line, delim); if (parts.length < 2) continue; const t = parts[0].trim(); const l = parts[parts.length - 1].trim(); if (!t || !l) continue; if (/^(text|sentence|review|document)$/i.test(t) && /^(label|class|target|sentiment)$/i.test(l)) continue; rows.push({ text: t, label: l }); } return rows; } function rng32(seed) { return function() { seed |= 0; seed = seed + 0x6D2B79F5 | 0; let t = Math.imul(seed ^ seed >>> 15, 1 | seed); t = t + Math.imul(t ^ t >>> 7, 61 | t) ^ t; return ((t ^ t >>> 14) >>> 0) / 4294967296; }; } function shuffle(arr, rng) { const a = arr.slice(); for (let i = a.length - 1; i > 0; i--) { const j = Math.floor(rng() * (i + 1)); [a[i], a[j]] = [a[j], a[i]]; } return a; } function group(rows) { const by = new Map(); for (const r of rows) { if (!by.has(r.label)) by.set(r.label, []); by.get(r.label).push(r); } return by; } function splitRows(rows, frac = 0.2) { const by = group(rows); if (by.size < 2) throw new Error("need at least two labels"); const rng = rng32(42); const train = [], test = []; for (const [label, arr] of by) { if (arr.length < 2) throw new Error("label '" + label + "' needs at least 2 examples"); const sh = shuffle(arr, rng); const nTest = Math.max(1, Math.round(arr.length * frac)); test.push(...sh.slice(0, nTest)); train.push(...sh.slice(nTest)); } return { train, test }; } function sampleTrain(train, n) { if (!n || n >= train.length) return train.slice(); const by = group(train); const per = Math.ceil(n / by.size); const rng = rng32(7); const out = []; for (const [_, arr] of by) out.push(...shuffle(arr, rng).slice(0, per)); return shuffle(out, rng).slice(0, n); } function tokens(s) { return [...new Set((s.toLowerCase().match(/[\p{L}\p{N}]{2,}/gu) || []))]; } function topTokens(rows, n) { const freq = new Map(); for (const r of rows) for (const t of tokens(r.text)) freq.set(t, (freq.get(t) || 0) + 1); return new Set([...freq.entries()].sort((a, b) => b[1] - a[1]).slice(0, n).map(x => x[0])); } function trainCNB(rows, maxVocab) { const labels = [...new Set(rows.map(r => r.label))].sort(); const keep = maxVocab ? topTokens(rows, maxVocab) : null; const counts = {}, totals = {}, featureAll = new Map(), vocab = new Set(); for (const l of labels) { counts[l] = new Map(); totals[l] = 0; } for (const r of rows) { for (const t of tokens(r.text)) { if (keep && !keep.has(t)) continue; counts[r.label].set(t, (counts[r.label].get(t) || 0) + 1); totals[r.label]++; vocab.add(t); featureAll.set(t, (featureAll.get(t) || 0) + 1); } } const allTot = [...featureAll.values()].reduce((a, b) => a + b, 0); return { labels, counts, totals, vocab, featureAll, allTot, alpha: 1, n: rows.length }; } function score(m, text) { const s = {}; for (const l of m.labels) s[l] = 0; for (const t of tokens(text)) { if (!m.vocab.has(t)) continue; const fa = m.featureAll.get(t); for (const l of m.labels) { const c = m.counts[l].get(t) || 0; const den = m.allTot + m.alpha * m.vocab.size - m.totals[l]; s[l] += -Math.log((fa + m.alpha - c) / den); } } let best = m.labels[0]; for (const l of m.labels) if (s[l] > s[best]) best = l; const mx = Math.max(...m.labels.map(l => s[l])); const ex = {}; let sum = 0; for (const l of m.labels) { ex[l] = Math.exp(s[l] - mx); sum += ex[l]; } const probs = {}; for (const l of m.labels) probs[l] = ex[l] / sum; return { label: best, probs, scores: s }; } function fmtKB(bytes) { return (bytes / 1024).toFixed(bytes < 10240 ? 1 : 0) + " KB"; } function wilson(ok, n, z = 1.96) { if (!n) return [0, 0]; const p = ok / n, z2 = z * z; const den = 1 + z2 / n; const centre = p + z2 / (2 * n); const half = z * Math.sqrt((p * (1 - p) + z2 / (4 * n)) / n); return [Math.max(0, (centre - half) / den), Math.min(1, (centre + half) / den)]; } function labelMetrics(per, labels) { return labels.map(l => { const x = per[l] || { ok: 0, n: 0, predicted: 0 }; const precision = x.predicted ? x.ok / x.predicted : null; const recall = x.n ? x.ok / x.n : null; const f1 = precision != null && recall != null && precision + recall > 0 ? 2 * precision * recall / (precision + recall) : null; return { label: l, support: x.n, correct: x.ok, predicted: x.predicted, precision, recall, f1 }; }); } function softmaxScores(scores, labels, T = 1) { const mx = Math.max(...labels.map(l => scores[l] / T)); const ex = {}; let sum = 0; for (const l of labels) { ex[l] = Math.exp(scores[l] / T - mx); sum += ex[l]; } const probs = {}; for (const l of labels) probs[l] = ex[l] / sum; return probs; } function fitTemperature(preds, labels) { const grid = [0.25, 0.33, 0.5, 0.67, 0.8, 1, 1.25, 1.5, 2, 2.5, 3, 4, 5, 7, 10]; let bestT = 1, best = Infinity; for (const T of grid) { let nll = 0; for (const p of preds) { const probs = softmaxScores(p.scores, labels, T); nll -= Math.log(Math.max(probs[p.trueLabel] || 0, 1e-12)); } nll /= Math.max(preds.length, 1); if (nll < best) { best = nll; bestT = T; } } return bestT; } function calibrationStats(preds, labels) { let brier = 0; for (const p of preds) { for (const l of labels) { const y = l === p.trueLabel ? 1 : 0; const q = p.probs[l] || 0; brier += (q - y) ** 2; } } brier /= Math.max(preds.length, 1); const rawBins = Array.from({ length: 10 }, (_, i) => ({ lo: i / 10, hi: (i + 1) / 10, n: 0, conf: 0, ok: 0 })); for (const p of preds) { const conf = Math.max(...labels.map(l => p.probs[l] || 0)); const idx = Math.min(9, Math.max(0, Math.floor(conf * 10))); const bin = rawBins[idx]; bin.n++; bin.conf += conf; bin.ok += p.pred === p.trueLabel ? 1 : 0; } const used = rawBins.filter(x => x.n > 0); const ece = used.reduce((a, x) => a + (x.n / preds.length) * Math.abs(x.ok / x.n - x.conf / x.n), 0); return { brier, ece, bins: used.map(x => ({ lo: x.lo, hi: x.hi, n: x.n, conf: x.conf / x.n, acc: x.ok / x.n })) }; } function median(xs) { const s = [...xs].sort((a, b) => a - b); const m = Math.floor(s.length / 2); return s.length % 2 ? s[m] : (s[m - 1] + s[m]) / 2; } function makeFolds(rows, k = 5) { const by = new Map(); rows.forEach((r, i) => { if (!by.has(r.label)) by.set(r.label, []); by.get(r.label).push(i); }); if (by.size < 2) throw new Error("need at least two labels"); const minCount = Math.min(...[...by.values()].map(a => a.length)); const actual = Math.min(k, minCount); if (actual < 2) throw new Error("5-fold CV needs at least 2 examples per label"); const rng = rng32(123); const foldOf = new Array(rows.length).fill(0); for (const inds of by.values()) { const shuffled = shuffle(inds, rng); shuffled.forEach((idx, j) => { foldOf[idx] = j % actual; }); } const folds = Array.from({ length: actual }, (_, f) => ({ fold: f + 1, train: [], test: [] })); rows.forEach((r, i) => { const f = foldOf[i]; folds[f].test.push(r); for (let j = 0; j < actual; j++) if (j !== f) folds[j].train.push(r); }); return { k: actual, folds }; } function parseAndShow() { try { const rows = parseData(document.getElementById("data").value); if (rows.length < 6) throw new Error("need at least 6 rows"); const by = group(rows); if (by.size < 2) throw new Error("need at least two labels"); state.rows = rows; state.split = splitRows(rows); state.model = null; document.getElementById("dataInfo").textContent = `${rows.length} rows · ${by.size} labels · ${state.split.train.length} train / ` + `${state.split.test.length} test`; document.getElementById("trainInfo").textContent = "Ready to train."; document.getElementById("metrics").innerHTML = ""; document.getElementById("confusion").innerHTML = ""; document.getElementById("try").style.display = "none"; document.getElementById("export").disabled = true; document.getElementById("cardgo").disabled = true; document.getElementById("pdfgo").disabled = true; document.getElementById("cvgo").disabled = true; document.getElementById("cvout").innerHTML = ""; document.getElementById("qrgo").disabled = true; document.getElementById("favgo").disabled = true; document.getElementById("wavgo").disabled = true; document.getElementById("qrout").innerHTML = ""; state.candidates = null; state.report = null; state.cv = null; } catch (e) { document.getElementById("dataInfo").innerHTML = `<span class="err">${esc(e.message)}</span>`; } } function doTrain() { if (!state.rows.length) { parseAndShow(); if (!state.rows.length) return; } const b = document.getElementById("budget").value; const n = b === "all" ? null : Number(b); const rows = sampleTrain(state.split.train, n); const t0 = performance.now(); const model = trainCNB(rows); const trainMs = performance.now() - t0; let ok = 0; const per = {}, confusion = {}; for (const l of model.labels) { per[l] = { ok: 0, n: 0, predicted: 0 }; confusion[l] = {}; for (const k of model.labels) confusion[l][k] = 0; } for (const r of state.split.test) { const p = score(model, r.text).label; const good = p === r.label; if (good) ok++; if (per[r.label]) per[r.label].n++; if (per[p]) per[p].predicted++; if (good && per[r.label]) per[r.label].ok++; if (confusion[r.label] && confusion[r.label][p] !== undefined) confusion[r.label][p]++; } const acc = ok / Math.max(state.split.test.length, 1); const ci = wilson(ok, state.split.test.length); const weights = new Blob([JSON.stringify(qrPayload(model, acc))]).size; const dataBytes = new Blob([JSON.stringify(rows)]).size; state.model = model; state.modelRows = rows; state.labels = model.labels; state.acc = acc; state.report = { acc, ok, nTest: state.split.test.length, per, confusion, rows: rows.length, labels: model.labels, weights, dataBytes, trainMs, ci }; state.cv = null; document.getElementById("cvout").innerHTML = ""; document.getElementById("metrics").innerHTML = ` <div class="metrics"> <div><span>${(acc * 100).toFixed(1)}%</span><label>held-out accuracy</label></div> <div><span>${fmtKB(weights)}</span><label>full int8 weights</label></div> <div><span>${fmtKB(dataBytes)}</span><label>data artifact</label></div> <div><span>${rows.length}</span><label>training rows</label></div> </div> <p class="muted">Trained in ${trainMs.toFixed(0)} ms on ${rows.length} examples; ${state.split.test.length} held-out rows, 95% CI ${(ci[0] * 100).toFixed(1)}–${(ci[1] * 100).toFixed(1)}%. ${model.labels.length} labels. The full-vocabulary int8 weights are the model; the data artifact is the examples embedded in the single HTML file. Container exports retrain with at most 160 words.</p>`; const lm = labelMetrics(per, model.labels); const pct = x => x == null ? "—" : (x * 100).toFixed(1) + "%"; const metricRows = lm.map(m => `<tr><td>${esc(m.label)}</td><td class="n">${m.support}</td>` + `<td class="n">${pct(m.precision)}</td><td class="n">${pct(m.recall)}</td>` + `<td class="n">${pct(m.f1)}</td></tr>`).join(""); const cmHead = model.labels.map(l => `<th class="n">${esc(l)}</th>`).join(""); const cmRows = model.labels.map(t => `<tr><td>${esc(t)}</td>` + model.labels.map(p => `<td class="n${t === p ? " good" : ""}">${confusion[t][p]}</td>`).join("") + `</tr>`).join(""); document.getElementById("confusion").innerHTML = `<table><thead><tr><th>label</th><th class="n">support</th><th class="n">precision</th>` + `<th class="n">recall</th><th class="n">F1</th></tr></thead><tbody>${metricRows}</tbody></table>` + `<p class="muted">Metrics on ${state.split.test.length} held-out rows.</p>` + `<table><thead><tr><th>true / pred</th>${cmHead}</tr></thead><tbody>${cmRows}</tbody></table>` + `<p class="muted">Confusion matrix: rows are true labels, columns are predictions; the diagonal is correct.</p>`; document.getElementById("trainInfo").textContent = `Trained on ${rows.length} examples; data artifact ${fmtKB(dataBytes)}.`; document.getElementById("try").style.display = "block"; document.getElementById("export").disabled = false; document.getElementById("cardgo").disabled = false; document.getElementById("pdfgo").disabled = false; document.getElementById("cvgo").disabled = false; document.getElementById("qrgo").disabled = false; document.getElementById("favgo").disabled = false; document.getElementById("wavgo").disabled = false; state.candidates = null; document.getElementById("exportInfo").textContent = "The exported file contains the selected examples and the classifier; it runs offline."; document.getElementById("text").value = rows[0].text; classify(); } function runCV() { if (!state.rows.length) return; const btn = document.getElementById("cvgo"); const out = document.getElementById("cvout"); btn.disabled = true; out.innerHTML = '<p class="muted">Running 5-fold CV…</p>'; try { const b = document.getElementById("budget").value; const n = b === "all" ? null : Number(b); const { k, folds } = makeFolds(state.rows, 5); const allLabels = [...new Set(state.rows.map(r => r.label))].sort(); const predictions = []; const results = folds.map(f => { const train = sampleTrain(f.train, n); const m = trainCNB(train); let ok = 0; for (const r of f.test) { const res = score(m, r.text); const correct = res.label === r.label; if (correct) ok++; predictions.push({ fold: f.fold, trueLabel: r.label, pred: res.label, probs: res.probs, scores: res.scores }); } return { fold: f.fold, train: train.length, test: f.test.length, acc: ok / Math.max(f.test.length, 1) }; }); const mean = results.reduce((a, r) => a + r.acc, 0) / results.length; const variance = results.length > 1 ? results.reduce((a, r) => a + (r.acc - mean) ** 2, 0) / (results.length - 1) : 0; const std = Math.sqrt(variance); const min = Math.min(...results.map(r => r.acc)); const max = Math.max(...results.map(r => r.acc)); const gap = state.acc == null ? null : (state.acc - mean) * 100; const base = calibrationStats(predictions, allLabels); const tByFold = {}; for (const f of results) { const trainPreds = predictions.filter(p => p.fold !== f.fold); tByFold[f.fold] = fitTemperature(trainPreds, allLabels); } const calibrated = predictions.map(p => ({ ...p, probs: softmaxScores(p.scores, allLabels, tByFold[p.fold]) })); const scaled = calibrationStats(calibrated, allLabels); const ts = Object.values(tByFold); const tMed = median(ts), tMin = Math.min(...ts), tMax = Math.max(...ts); const brier = base.brier, ece = base.ece, bins = base.bins; state.cv = { k, mean, std, min, max, results, rows: state.rows.length, budget: b, holdout: state.acc, gap, brier, ece, bins, predictions: predictions.length, temperature: { median: tMed, min: tMin, max: tMax, byFold: tByFold, brier0: base.brier, ece0: base.ece, brierT: scaled.brier, eceT: scaled.ece, binsT: scaled.bins } }; const pct = x => (x * 100).toFixed(1) + "%"; const body = results.map(r => `<tr><td>${r.fold}</td><td class="n">${r.train}</td>` + `<td class="n">${r.test}</td><td class="n">${pct(r.acc)}</td></tr>`).join(""); const calRows = bins.map(x => `<tr><td>${x.lo.toFixed(1)}–${x.hi.toFixed(1)}</td>` + `<td class="n">${x.n}</td><td class="n">${pct(x.conf)}</td>` + `<td class="n">${pct(x.acc)}</td></tr>`).join(""); const gapAbs = gap == null ? null : Math.abs(gap); const gapText = gap == null ? "" : gapAbs < 0.05 ? ` CV mean matches the 80/20 holdout (${pct(state.acc)}).` : ` CV mean is ${gapAbs.toFixed(1)} pp ${gap >= 0 ? "lower" : "higher"} ` + `than the 80/20 holdout (${pct(state.acc)}).`; out.innerHTML = `<div class="cvhead"><b>${k}-fold CV:</b> ${pct(mean)} mean · ` + `${(std * 100).toFixed(1)} pp fold std · range ${pct(min)}–${pct(max)}</div>` + `<table><thead><tr><th>fold</th><th class="n">train</th><th class="n">test</th>` + `<th class="n">accuracy</th></tr></thead><tbody>${body}</tbody></table>` + `<p class="muted">Brier <b>${brier.toFixed(3)}</b> · ECE <b>${ece.toFixed(3)}</b> ` + `over ${bins.length} non-empty bins, ${predictions.length} out-of-fold predictions.</p>` + `<p class="muted">Temperature scaling (nested out-of-fold): T median ` + `<b>${tMed.toFixed(2)}</b> (${tMin.toFixed(2)}–${tMax.toFixed(2)}) · ` + `ECE ${ece.toFixed(3)} → ${scaled.ece.toFixed(3)} · ` + `Brier ${brier.toFixed(3)} → ${scaled.brier.toFixed(3)}. ` + `Applied to this page's display only; exports unchanged.</p>` + `<details><summary>Reliability bins (T=1)</summary><table><thead><tr><th>confidence</th>` + `<th class="n">n</th><th class="n">mean conf</th><th class="n">accuracy</th></tr></thead>` + `<tbody>${calRows}</tbody></table></details>` + `<p class="muted">All ${state.rows.length} rows; budget ` + `${b === "all" ? "all" : b + " examples"} per training fold.${gapText} ` + `The fold-to-fold spread is a stability check, not a confidence interval.</p>`; } catch (e) { out.innerHTML = `<p class="err">${esc(e.message)}</p>`; state.cv = null; } finally { btn.disabled = false; } } function classify() { if (!state.model) return; const text = document.getElementById("text").value.trim(); if (!text) return; const res = score(state.model, text); const T = state.cv?.temperature?.median || 1; const probs = T === 1 ? res.probs : softmaxScores(res.scores, state.model.labels, T); const rows = state.model.labels.map(l => { const p = (probs[l] || 0) * 100; return `<div class="bar-row"><span>${esc(l)}</span><span class="bar"><i style="width:${p.toFixed(1)}%"></i></span><span>${p.toFixed(1)}%</span></div>`; }).join(""); const note = T === 1 ? "Scores are a softmax over Complement NB weights, not calibrated." : `Temperature-scaled with T=${T.toFixed(2)} for display only; exports are unchanged.`; document.getElementById("out").innerHTML = `<div class="verdict">${esc(res.label)}</div><div class="bars">${rows}</div> <p class="muted">${note}</p>`; } function buildExport(rows, labels, acc) { const payload = JSON.stringify({ rows, labels }).replace(/</g, "\\u003c"); const fn = [tokens.toString(), trainCNB.toString(), score.toString()].join("\n"); const kb = fmtKB(new Blob([JSON.stringify(rows)]).size); return `<!doctype html> <html lang="en"><head><meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Tiny AI — ${kb}</title> <style> body{margin:0;background:#0f1115;color:#e8e6e3;font:16px/1.55 -apple-system,"Segoe UI",Roboto,sans-serif} main{max-width:760px;margin:0 auto;padding:44px 22px 80px} h1{font-size:34px;letter-spacing:-.6px;margin:0 0 8px} .badge{display:inline-block;background:#6ee7b7;color:#06281d;font-weight:800;padding:6px 10px;border-radius:6px;font-size:14px} .panel{background:#171a21;border:1px solid #232733;border-radius:12px;padding:18px;margin:16px 0} textarea{width:100%;background:#0d1015;color:#e8e6e3;border:1px solid #232733;border-radius:8px;padding:12px;font:inherit} button{margin-top:10px;padding:11px 16px;border:0;border-radius:8px;background:#6ee7b7;color:#06281d;font-weight:750;font-size:15px;cursor:pointer} .muted{color:#9aa0aa;font-size:13px} .verdict{font-size:22px;font-weight:750;margin:14px 0 8px} .bar-row{display:grid;grid-template-columns:110px 1fr 54px;gap:8px;align-items:center;font-size:13px;margin:5px 0} .bar{height:10px;background:#0d1015;border-radius:5px;overflow:hidden} .bar>i{display:block;height:100%;background:#6ee7b7;width:0} .bar-row span:last-child{text-align:right;color:#9aa0aa} </style></head><body><main> <div class="badge">${kb} · ${rows.length} examples</div> <h1>A tiny text classifier</h1> <p class="muted">This file contains its own training data and fits a Complement Naive Bayes when it loads. No server, no weights, no network calls. Held-out accuracy in the maker: ${(acc * 100).toFixed(1)}%.</p> <div class="panel"><textarea id="text" rows="3" placeholder="Paste a text…"></textarea> <button id="go">Classify</button><div id="out"></div></div> <p class="muted">Build one from your own data: Tiny AI Maker.</p> </main> <script> const DATA = ${payload}; ${fn} const model = trainCNB(DATA.rows); document.getElementById("text").value = DATA.rows[0].text; document.getElementById("go").onclick = () => { const text = document.getElementById("text").value.trim(); if (!text) return; const res = score(model, text); const rows = DATA.labels.map(l => { const p = (res.probs[l] || 0) * 100; return '<div class="bar-row"><span>' + l.replace(/[&<>"']/g, c => ({"&":"&amp;","<":"&lt;",">":"&gt;",'"':"&quot;","'":"&#39;"}[c])) + '</span><span class="bar"><i style="width:' + p.toFixed(1) + '%"></i></span><span>' + p.toFixed(1) + '%</span></div>'; }).join(""); document.getElementById("out").innerHTML = '<div class="verdict">' + res.label + '</div><div class="bars">' + rows + '</div><p class="muted">Softmax over Complement NB weights; not calibrated.</p>'; }; <\/script></body></html>`; } function b64url(bytes) { let s = ""; for (let i = 0; i < bytes.length; i++) s += String.fromCharCode(bytes[i]); return btoa(s).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); } function qrPayload(model, acc) { const labels = model.labels; const words = [...model.vocab]; const V = words.length; const q = new Int8Array(labels.length * V); const scales = []; for (let c = 0; c < labels.length; c++) { const w = words.map(t => { const cnt = model.counts[labels[c]].get(t) || 0; const den = model.allTot + model.alpha * V - model.totals[labels[c]]; return -Math.log((model.featureAll.get(t) + model.alpha - cnt) / den); }); const mx = Math.max(...w.map(Math.abs)) || 1; const sc = mx / 127; scales.push(sc); for (let i = 0; i < V; i++) { q[c * V + i] = Math.max(-127, Math.min(127, Math.round(w[i] / sc))); } } return { l: labels, v: words, w: b64url(new Uint8Array(q.buffer)), s: scales, a: Number(acc.toFixed(4)), n: model.n }; } function candidates() { if (state.candidates) return state.candidates; const test = state.split.test; const list = []; for (const K of [160, 120, 90, 70, 50, 40]) { const m = trainCNB(state.modelRows, K); let ok = 0; for (const r of test) if (score(m, r.text).label === r.label) ok++; const acc = ok / Math.max(test.length, 1); const payload = qrPayload(m, acc); const raw = new TextEncoder().encode(JSON.stringify(payload)); list.push({ K, m, acc, raw }); } state.candidates = list; return list; } function downloadBlob(blob, name) { const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = name; document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(a.href), 5000); } function buildQR() { const out = document.getElementById("qrout"); if (!state.model) { out.textContent = "Train first."; return; } if (typeof qrcode !== "function") { out.innerHTML = '<p class="err">QR library not loaded.</p>'; return; } const base = new URL("qr.html", location.href).href; for (const c of candidates()) { const frag = b64url(c.raw); const url = base + "#m=" + frag; if (url.length > 2850) continue; try { const qr = qrcode(0, "L"); qr.addData(url); qr.make(); const img = qr.createDataURL(8, 4); window.__lastQR = url; out.innerHTML = `<img class="qr" src="${img}" alt="QR model"> <p class="muted">QR model: <b>${c.m.vocab.size} words</b>, <b>${(url.length / 1024).toFixed(1)} KB URL</b>, <b>${(c.acc * 100).toFixed(1)}%</b> on the held-out split. Scan or open the URL.</p> <p><a href="${url}" target="_blank" rel="noopener">Open the model URL</a> · <a download="tiny-ai-qr.png" href="${img}">Download QR PNG</a></p>`; return; } catch (e) { // too dense; try a smaller vocabulary } } out.innerHTML = '<p class="err">Too large for a scannable QR. Reduce labels or the training budget.</p>'; } function downloadFavicon() { const out = document.getElementById("qrout"); if (!state.model) { out.textContent = "Train first."; return; } const c = candidates().find(x => x.raw.length + 4 <= 32 * 32 * 3); if (!c) { out.innerHTML = '<p class="err">Too large for a 32×32 favicon. Reduce labels or the budget.</p>'; return; } const bytes = new Uint8Array(32 * 32 * 3); new DataView(bytes.buffer).setUint32(0, c.raw.length, true); bytes.set(c.raw, 4); const canvas = document.createElement("canvas"); canvas.width = 32; canvas.height = 32; const ctx = canvas.getContext("2d"); const img = ctx.createImageData(32, 32); for (let i = 0; i < 32 * 32; i++) { img.data[i * 4] = bytes[i * 3]; img.data[i * 4 + 1] = bytes[i * 3 + 1]; img.data[i * 4 + 2] = bytes[i * 3 + 2]; img.data[i * 4 + 3] = 255; } ctx.putImageData(img, 0, 0); canvas.toBlob(blob => downloadBlob(blob, "tiny-ai-favicon.png"), "image/png"); out.innerHTML = `<p class="muted">Favicon: <b>${c.m.vocab.size} words</b>, <b>${(c.raw.length / 1024).toFixed(1)} KB model</b>, <b>${(c.acc * 100).toFixed(1)}%</b>. Download started; the viewer is <code>favicon.html</code>.</p>`; } function writeStr(dv, off, s) { for (let i = 0; i < s.length; i++) dv.setUint8(off + i, s.charCodeAt(i)); } function downloadWav() { const out = document.getElementById("qrout"); if (!state.model) { out.textContent = "Train first."; return; } const c = candidates()[0]; const data = new Uint8Array(4 + c.raw.length); new DataView(data.buffer).setUint32(0, c.raw.length, true); data.set(c.raw, 4); const h = new ArrayBuffer(44); const dv = new DataView(h); writeStr(dv, 0, "RIFF"); dv.setUint32(4, 36 + data.length, true); writeStr(dv, 8, "WAVE"); writeStr(dv, 12, "fmt "); dv.setUint32(16, 16, true); dv.setUint16(20, 1, true); dv.setUint16(22, 1, true); dv.setUint32(24, 8000, true); dv.setUint32(28, 8000, true); dv.setUint16(32, 1, true); dv.setUint16(34, 8, true); writeStr(dv, 36, "data"); dv.setUint32(40, data.length, true); downloadBlob(new Blob([h, data], { type: "audio/wav" }), "tiny-ai.wav"); out.innerHTML = `<p class="muted">WAV: <b>${c.m.vocab.size} words</b>, <b>${(data.length / 1024).toFixed(1)} KB</b>, <b>${(c.acc * 100).toFixed(1)}%</b>. Download started; the viewer is <code>audio.html</code>.</p>`; } function downloadCard() { const r = state.report; if (!r) return; const cv = state.cv; const pct = x => x == null ? "—" : (x * 100).toFixed(1) + "%"; const md = s => String(s).replace(/\|/g, "\\|"); const lm = labelMetrics(r.per, r.labels); const metrics = lm.map(m => `| ${md(m.label)} | ${m.support} | ${pct(m.precision)} | ${pct(m.recall)} | ${pct(m.f1)} |`).join("\n"); const cmHead = `| true / pred | ${r.labels.map(md).join(" | ")} |`; const cmSep = `|---|${r.labels.map(() => "---:").join("|")}|`; const cmRows = r.labels.map(t => `| ${md(t)} | ${r.labels.map(p => r.confusion[t][p]).join(" | ")} |`).join("\n"); const card = `# Tiny AI model card Generated ${new Date().toISOString().slice(0, 10)} by Tiny AI Maker, in the browser. ## Task - labels: ${r.labels.join(", ")} - training rows: ${r.rows} - held-out rows: ${r.nTest} (80/20 split, seed 42) ## Measured - held-out accuracy: ${pct(r.acc)} - 95% Wilson interval: ${pct(r.ci[0])}–${pct(r.ci[1])} - int8 weights (full vocabulary): ${r.weights} B (Complement NB, JSON) - data artifact: ${r.dataBytes} B (examples + classifier, single HTML) - fit time: ${r.trainMs.toFixed(0)} ms in this browser ${cv ? `- ${cv.k}-fold CV: ${pct(cv.mean)} mean vs ${pct(cv.holdout)} holdout, ${(cv.std * 100).toFixed(1)} pp fold std` : ""} ${cv ? `- Brier: ${cv.brier.toFixed(3)}; ECE: ${cv.ece.toFixed(3)} (${cv.k}-fold out-of-fold)` : ""} ${cv ? `- temperature scaling: T median ${cv.temperature.median.toFixed(2)} (${cv.temperature.min.toFixed(2)}–${cv.temperature.max.toFixed(2)}); ECE ${cv.ece.toFixed(3)} → ${cv.temperature.eceT.toFixed(3)}; Brier ${cv.brier.toFixed(3)} → ${cv.temperature.brierT.toFixed(3)} (not applied to exports)` : ""} ${cv ? ` ## Cross-validation - ${cv.k}-fold CV on ${cv.rows} rows; budget ${cv.budget === "all" ? "all" : cv.budget + " examples"} per training fold - mean ${pct(cv.mean)}, fold std ${(cv.std * 100).toFixed(1)} pp, range ${pct(cv.min)}–${pct(cv.max)} - 80/20 holdout: ${pct(cv.holdout)}; CV mean differs by ${Math.abs(cv.gap).toFixed(1)} pp - calibration: Brier ${cv.brier.toFixed(3)}, ECE ${cv.ece.toFixed(3)} over ${cv.bins.length} non-empty bins (${cv.predictions} predictions) - temperature scaling: median T ${cv.temperature.median.toFixed(2)} (${cv.temperature.min.toFixed(2)}–${cv.temperature.max.toFixed(2)}); ECE ${cv.ece.toFixed(3)} → ${cv.temperature.eceT.toFixed(3)}; Brier ${cv.brier.toFixed(3)} → ${cv.temperature.brierT.toFixed(3)} (measured, not applied to exports) - folds: ${cv.results.map(x => `${x.fold}: ${pct(x.acc)}`).join(", ")} - The exported model is the 80/20 fit above; CV is a stability check, not a confidence interval. ` : ""} ## Per-label metrics | label | support | precision | recall | F1 | |---|---:|---:|---:|---:| ${metrics} ## Confusion matrix ${cmHead} ${cmSep} ${cmRows} ## Caveats - Headline accuracy is one 80/20 split. ${cv ? "The 5-fold CV above is a stability check; the folds share data." : "The Wilson interval reflects test size only; it is not an estimate of dataset noise."} - Bag-of-words Complement NB: no word order, no embeddings. ${cv ? `- Calibration is out-of-fold, but with ${cv.rows} rows the bins are noisy; ECE is not a guarantee. Temperature scaling is measured, not applied to the exported weights.` : ""} - Not an LLM and not a production classifier. - Container exports may use a smaller vocabulary than the full model. Their pages report the accuracy of the exported vocabulary. - The numbers come from this page's own run; no independent audit. `; downloadBlob(new Blob([card], { type: "text/markdown" }), "tiny-ai-model-card.md"); document.getElementById("exportInfo").textContent = "Downloaded tiny-ai-model-card.md with the split, accuracy, interval, sizes" + (cv ? " and 5-fold CV." : "."); } function pdfEsc(s) { return String(s).replace(/\\/g, "\\\\").replace(/\(/g, "\\(").replace(/\)/g, "\\)"); } function ascii(s) { return String(s).replace(/[^\x20-\x7e]/g, "?"); } async function downloadPdfCard() { const r = state.report; if (!r) return; const cv = state.cv; const pct = x => (x * 100).toFixed(1); const weights = qrPayload(state.model, state.acc); const raw = new TextEncoder().encode(JSON.stringify(weights)); const payload = b64url(raw); let sha = ""; try { const digest = await crypto.subtle.digest("SHA-256", raw); sha = [...new Uint8Array(digest)].map(b => b.toString(16).padStart(2, "0")).join(""); } catch (e) { sha = ""; } const lm = labelMetrics(r.per, r.labels); const metrics = lm.slice(0, 8).map(m => { const f = x => x == null ? "?" : pct(x); return ` ${ascii(m.label).slice(0, 20)}: P ${f(m.precision)}% R ${f(m.recall)}% ` + `F1 ${f(m.f1)}% (n=${m.support})`; }); if (r.labels.length > 8) metrics.push(` ... ${r.labels.length - 8} more labels`); const labelLine = r.labels.map(ascii).join(", "); const lines = [ "Tiny AI model card", "Generated " + new Date().toISOString().slice(0, 10) + " by Tiny AI Maker, in the browser.", "", "Labels: " + (labelLine.length > 70 ? labelLine.slice(0, 67) + "..." : labelLine), "Training rows: " + r.rows, "Held-out rows: " + r.nTest + " (80/20 split, seed 42)", "Accuracy: " + pct(r.acc) + "% (95% CI " + pct(r.ci[0]) + "-" + pct(r.ci[1]) + "%)", ...(cv ? [`CV (${cv.k}-fold): ${pct(cv.mean)}% mean vs ${pct(cv.holdout)}% holdout, ${(cv.std * 100).toFixed(1)} pp std`] : []), ...(cv ? [`Brier ${cv.brier.toFixed(3)}, ECE ${cv.ece.toFixed(3)}`] : []), ...(cv ? [`Temperature: T ${cv.temperature.median.toFixed(2)}, ECE ${cv.ece.toFixed(3)} -> ${cv.temperature.eceT.toFixed(3)}`] : []), "Full int8 weights: " + r.weights + " bytes", sha ? "SHA-256: " + sha : "SHA-256: unavailable", "Data artifact: " + r.dataBytes + " bytes (examples + classifier)", "", "Per-label precision / recall / F1:", ...metrics, "", "Caveats:", cv ? " The 5-fold CV above is a stability check; the exported model is the 80/20 fit." : " One 80/20 split, not cross-validation.", " Bag-of-words Complement NB; no word order, no calibration.", " Not an LLM and not a production classifier.", " The model is in /Keywords metadata, not drawn on this page.", "Open pdf.html, load this file and classify." ]; const parts = ["BT", "/F1 20 Tf", "72 720 Td", `(${pdfEsc(lines[0])}) Tj`, "/F1 11 Tf", "0 -28 Td"]; for (const line of lines.slice(1)) { if (line) parts.push(`(${pdfEsc(line)}) Tj`); parts.push("0 -16 Td"); } parts.push("ET"); const stream = parts.join("\n"); const hashField = sha ? `/TinyAISHA256 (${sha}) ` : ""; const info = `<< /Title (${pdfEsc("Tiny AI model card")}) ` + `/Author (${pdfEsc("Tiny AI Maker")}) ` + `/Subject (${pdfEsc("A browser-trained classifier in /Keywords")}) ` + `${hashField}/Keywords (${payload}) /Creator (${pdfEsc("demo/maker.html")}) ` + `/Producer (${pdfEsc("stream-finetune")}) >>`; const objs = [ "<< /Type /Catalog /Pages 2 0 R >>", "<< /Type /Pages /Kids [3 0 R] /Count 1 >>", "<< /Type /Page /Parent 2 0 R /MediaBox [0 0 612 792] /Contents 4 0 R " + "/Resources << /Font << /F1 5 0 R >> >> >>", `<< /Length ${stream.length} >>\nstream\n${stream}\nendstream`, "<< /Type /Font /Subtype /Type1 /BaseFont /Helvetica >>", info ]; let out = "%PDF-1.4\n%\xE2\xE3\xCF\xD3\n"; const offsets = [0]; for (let i = 1; i <= 6; i++) { offsets.push(out.length); out += `${i} 0 obj\n${objs[i - 1]}\nendobj\n`; } const xref = out.length; out += "xref\n0 7\n0000000000 65535 f \n"; for (let i = 1; i <= 6; i++) { out += String(offsets[i]).padStart(10, "0") + " 00000 n \n"; } out += `trailer\n<< /Size 7 /Root 1 0 R /Info 6 0 R >>\nstartxref\n${xref}\n%%EOF\n`; const bytes = new Uint8Array(out.length); for (let i = 0; i < out.length; i++) bytes[i] = out.charCodeAt(i) & 255; downloadBlob(new Blob([bytes], { type: "application/pdf" }), "tiny-ai-model-card.pdf"); document.getElementById("exportInfo").textContent = "Downloaded tiny-ai-model-card.pdf. The model is in /Keywords; open pdf.html and load it. " + (sha ? "SHA-256 included." : "SHA-256 unavailable in this context."); } function download() { if (!state.model) return; const html = buildExport(state.modelRows, state.labels, state.acc); const blob = new Blob([html], { type: "text/html" }); const a = document.createElement("a"); a.href = URL.createObjectURL(blob); a.download = "tiny-ai.html"; document.body.appendChild(a); a.click(); a.remove(); setTimeout(() => URL.revokeObjectURL(a.href), 5000); document.getElementById("exportInfo").textContent = "Downloaded tiny-ai.html. Open it anywhere; it trains from the embedded examples."; } document.getElementById("sample").onclick = () => { document.getElementById("data").value = JSON.stringify(SAMPLE); parseAndShow(); }; document.getElementById("sms").onclick = () => { document.getElementById("data").value = JSON.stringify(SMS_SAMPLE); parseAndShow(); }; document.getElementById("parse").onclick = parseAndShow; document.getElementById("file").onchange = (e) => { const f = e.target.files[0]; if (!f) return; const r = new FileReader(); r.onload = () => { document.getElementById("data").value = r.result; parseAndShow(); }; r.readAsText(f); }; document.getElementById("train").onclick = doTrain; document.getElementById("cvgo").onclick = runCV; document.getElementById("budget").onchange = () => { state.cv = null; document.getElementById("cvout").innerHTML = ""; document.getElementById("cvgo").disabled = !state.model; }; document.getElementById("classify").onclick = classify; document.getElementById("export").onclick = download; document.getElementById("cardgo").onclick = downloadCard; document.getElementById("pdfgo").onclick = () => { downloadPdfCard().catch(e => { document.getElementById("exportInfo").textContent = "PDF export failed: " + e; }); }; document.getElementById("qrgo").onclick = buildQR; document.getElementById("favgo").onclick = downloadFavicon; document.getElementById("wavgo").onclick = downloadWav; </script> </body> </html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Tiny AI Maker — train a classifier in your browser</title>
<style>
:root { --bg:#0f1115; --panel:#171a21; --fg:#e8e6e3; --muted:#9aa0aa;
--accent:#6ee7b7; --warn:#fbbf24; --line:#232733; }
* { box-sizing: border-box; }
body { margin:0; background:var(--bg); color:var(--fg);
font:16px/1.55 -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; }
main { max-width: 900px; margin:0 auto; padding: 44px 22px 80px; }
h1 { font-size: clamp(30px, 5vw, 46px); line-height:1.05; margin: 14px 0 10px;
letter-spacing:-0.8px; }
h2 { font-size: 20px; margin: 0 0 10px; }
p { margin: 0 0 12px; }
.lead { color:var(--muted); font-size:18px; margin:0 0 26px; max-width: 740px; }
.badge { display:inline-block; background:var(--accent); color:#06281d;
font-weight:800; font-size:14px; letter-spacing:0.5px;
padding:6px 10px; border-radius:6px; }
.panel { background:var(--panel); border:1px solid var(--line); border-radius:12px;
padding:18px; margin:16px 0; }
.muted { color:var(--muted); font-size:13px; }
textarea { width:100%; background:#0d1015; color:var(--fg); border:1px solid var(--line);
border-radius:8px; padding:12px; font:inherit; resize:vertical; }
input[type=file] { color:var(--muted); margin-top:10px; }
button { border:0; border-radius:8px; cursor:pointer; font:inherit; }
.go { margin-top:12px; padding:12px 16px; background:var(--accent); color:#06281d;
font-weight:750; font-size:15px; }
.go:hover { filter:brightness(1.06); }
.chip { border:1px solid var(--line); background:#0d1015; color:var(--fg);
padding:8px 10px; border-radius:8px; cursor:pointer; font-size:14px; }
.chip:hover { border-color:#3a4150; }
.chips { display:flex; gap:8px; flex-wrap:wrap; margin-top:10px; }
select { background:#0d1015; color:var(--fg); border:1px solid var(--line);
border-radius:8px; padding:8px; font:inherit; }
.metrics { display:grid; grid-template-columns:repeat(4,1fr); gap:12px; margin:12px 0; }
.metrics div { text-align:center; }
.metrics span { display:block; font-size:24px; font-weight:750; color:var(--accent); }
.metrics label { font-size:12px; color:var(--muted); }
table { width:100%; border-collapse:collapse; font-size:14px; margin-top:10px; }
th, td { text-align:left; padding:6px; border-bottom:1px solid var(--line); }
th { color:var(--muted); font-weight:600; font-size:12px; }
td.n { text-align:right; font-variant-numeric:tabular-nums; }
td.good { color:var(--accent); font-weight:700; }
.cvhead { margin-top:12px; font-size:14px; }
.verdict { font-size:22px; font-weight:750; margin:14px 0 8px; }
.bar-row { display:grid; grid-template-columns: 110px 1fr 54px; gap:8px;
align-items:center; font-size:13px; margin:5px 0; }
.bar { height:10px; background:#0d1015; border-radius:5px; overflow:hidden; }
.bar > i { display:block; height:100%; background:var(--accent); width:0; }
.bar-row span:last-child { text-align:right; color:var(--muted); }
.err { color:#fca5a5; }
footer { margin-top:30px; color:var(--muted); font-size:13px; }
a { color:var(--accent); }
@media (max-width: 620px) { .metrics { grid-template-columns:repeat(2,1fr); } }
</style>
</head>
<body>
<main>
<header>
<div class="badge">browser-only</div>
<h1>Tiny AI Maker</h1>
<p class="lead">Bring a small labelled text dataset. This page fits a Complement Naive
Bayes in your browser, shows held-out accuracy with a confidence interval, an optional
5-fold CV with out-of-fold Brier/ECE, the int8 weight size and the example size, and
exports a single HTML file, a QR, a favicon, a WAV or a PDF model card. No data leaves
the page.</p>
</header>
<section class="panel">
<h2>1. Data</h2>
<p class="muted">CSV/TSV with two columns: <code>text,label</code>. Quote fields that
contain commas. JSONL with <code>{"text":"...","label":"..."}</code> also works.</p>
<textarea id="data" rows="8" placeholder="text,label&#10;The movie was great,positive&#10;The plot was dull,negative"></textarea>
<input id="file" type="file" accept=".csv,.tsv,.jsonl,.txt,.json">
<div class="chips">
<button class="chip" id="sample">Load AG News sample</button>
<button class="chip" id="sms">Load SMS spam sample</button>
<button class="chip" id="parse">Parse data</button>
</div>
<p class="muted" id="dataInfo"></p>
</section>
<section class="panel">
<h2>2. Train</h2>
<p class="muted">The model is the selected examples; the training code is shared. A
smaller budget means a smaller artifact and usually a little less accuracy.</p>
<label class="muted" for="budget">Artifact budget</label>
<select id="budget">
<option value="50">50 examples</option>
<option value="100" selected>100 examples</option>
<option value="250">250 examples</option>
<option value="500">500 examples</option>
<option value="1000">1,000 examples</option>
<option value="all">All training rows</option>
</select>
<button class="go" id="train">Train</button>
<p class="muted" id="trainInfo">Parse some data first.</p>