31. t-distributed Stochastic Neighbor Embedding#

Getting embeddings in lower dimension.

from google.colab import drive
drive.mount('/content/drive')  # Add My Drive/<>

import os
os.chdir('drive/My Drive')
os.chdir('Books_Writings/NLPBook/')
Mounted at /content/drive
%%capture
%pylab inline
import pandas as pd
import os
%load_ext rpy2.ipython

31.1. t-SNE Plots#

Here is the original t-SNE paper: https://www.jmlr.org/papers/volume9/vandermaaten08a/vandermaaten08a.pdf

Properties:

  1. t-SNE is slow as the dataset gets large.

  2. Distances within cluster are correct but not between cluster so it is not a clustering algorithm, it is a visualization algorithm.

  3. You can use it to project down a dataset into 2 or 3 dimensions. If you get separate groups, it suggests that a multiclass classifier may do a good job. See: https://colah.github.io/posts/2014-10-Visualizing-MNIST/

SNE stands for “Stochastic Neighbor Embedding”.

31.2. t-SNE Algorithm#

The basics of the algorithm are as follows, using the equations in the paper:

  1. Get a Gaussian measure of similarity of two points, represented by vectors \(x_i\) and \(x_j\) as follows:

\[ p_{j|i} = \frac{\exp(-\|x_i-x_j\|^2/2\sigma_i^2)}{\sum_{k \neq i}\exp(-\|x_i-x_k\|^2/2\sigma_i^2)}, \quad p_{j|i} \neq p_{i|j} \]
  1. \(x\) is in the high-dimensional space and we are projecting into points \(y_i\) and \(y_j\) in the low-dimension space, so we can define a similarity metric for the low-dimension space as well. We note that the variance chosen for the low-dimension enbedding is \(1/\sqrt{2}\).

\[ q_{j|i} = \frac{\exp(-\|y_i-y_j\|^2)}{\sum_{k \neq i}\exp(-\|y_i-y_k\|^2)}, \quad q_{i|i}=0 \]
  1. We want the distributions \(p\) and \(q\) to be as close as possible, and we define the distance between the two using the Kullback-Leibler (KL) divergence. We call this a “cost” (loss) function and minimize this.

\[ C = \sum_i KL(P_i \| Q_i) = \sum_i \sum_j p_{j|i} \log\frac{p_{j|i}}{q_{j|i}} \]

Here, \(P_i\) represents the conditional probability distribution over all other datapoints given datapoint \(x_i\), and \(Q_i\) represents the conditional probability distribution over all other map points given map point \(y_i\).

  1. How to set the parameter \(\sigma_i\)? This is done by choosing a desired perplexity parameter and setting it equal to

\[ Perp(P_i) = 2^{H(P_i)}, \quad H(P_i) = -\sum_j p_{j|i} log_2 p_{j|i} \]

where \(H(P_i)\) is Shannon entropy.

  1. Finally, minimize the loss function by taking derivatives wrt points \(y\):

\[ \frac{\partial C}{\partial y_i} = 2 \sum_j [p_{j|i}-q_{j|i}+p_{i|j}-q_{i|j}](y_i-y_j) \]

This is the dimension of \(y_i\).

Let’s see the t-SNE plot on the Reuters news dataset.

## Change Python version if needed
# !sudo apt-get install python3.9
# !sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.9 2
!python --version
Python 3.12.12
# Read in text cleaning functions
import nltk
nltk.download('punkt_tab')

# Remove punctuations
import string
def removePuncStr(s):
    for c in string.punctuation:
        s = s.replace(c," ")
    return s

def removePunc(text_array):
    return [removePuncStr(h) for h in text_array]

# Remove numbers
def removeNumbersStr(s):
    for c in range(10):
        n = str(c)
        s = s.replace(n," ")
    return s

def removeNumbers(text_array):
    return [removeNumbersStr(h) for h in text_array]

# Stemming
nltk.download('punkt')
from nltk.stem import PorterStemmer
from nltk.tokenize import sent_tokenize, word_tokenize

def stemText(text_array):
    stemmed_text = []
    for h in text_array:
        words = word_tokenize(h)
        h2 = ''
        for w in words:
            h2 = h2 + ' ' + PorterStemmer().stem(w)
        stemmed_text.append(h2)
    return stemmed_text

# Remove Stopwords
nltk.download('stopwords')
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize

def stopText(text_array):
    stop_words = set(stopwords.words('english'))
    stopped_text = []
    for h in text_array:
        words = word_tokenize(h)
        h2 = ''
        for w in words:
            if w not in stop_words:
                h2 = h2 + ' ' + w
        stopped_text.append(h2)
    return stopped_text

# Write all docs to separate files
def write2textfile(s,filename):
    text_file = open(filename, "w")
    text_file.write(s)
    text_file.close()
[nltk_data] Downloading package punkt_tab to /root/nltk_data...
[nltk_data]   Unzipping tokenizers/punkt_tab.zip.
[nltk_data] Downloading package punkt to /root/nltk_data...
[nltk_data]   Unzipping tokenizers/punkt.zip.
[nltk_data] Downloading package stopwords to /root/nltk_data...
[nltk_data]   Unzipping corpora/stopwords.zip.
%%time
import nltk
from nltk.corpus import PlaintextCorpusReader
corpus_root = 'NLP_data/reuters/training/'
ctext = PlaintextCorpusReader(corpus_root, '.*')
CPU times: user 20.1 ms, sys: 2.84 ms, total: 22.9 ms
Wall time: 25 s
%%time
#Convert corpus to text array with a full string for each doc
def merge_arrays(word_lists):
    wordlist = []
    for wl in word_lists:
        wordlist = wordlist + wl
    doc = ' '.join(wordlist)
    return doc

nltk.download('punkt')
#Run this through the corpus to get a word array for each doc
text_array = []
for p in ctext.paras():
    doc = merge_arrays(p)
    text_array.append(doc)

#Clean up the docs using the previous functions
news = text_array
news = removePunc(news)
news = removeNumbers(news)
news = stopText(news)
#news = stemText(news)
news = [j.lower() for j in news]

df = pd.DataFrame(news, columns=["Text"])
df.head()
[nltk_data] Downloading package punkt to /root/nltk_data...
[nltk_data]   Package punkt is already up-to-date!
CPU times: user 11.4 s, sys: 2.41 s, total: 13.8 s
Wall time: 4min 14s
Text
0 bahia cocoa review showers continued througho...
1 computer terminal systems lt cpml completes s...
2 n z trading bank deposit growth rises slightl...
3 national amusements again ups viacom lt via b...
4 rogers lt rog sees st qtr net up significantl...
#Create plain DTM
from sklearn.feature_extraction.text import CountVectorizer, TfidfVectorizer

docs = news
vec = TfidfVectorizer(min_df=0.01, max_df=0.9)
X = vec.fit_transform(docs)
dtm = pd.DataFrame(X.toarray(), columns=vec.get_feature_names_out())
print(dtm.shape)
dtm
(8471, 953)
able accepted accord according account accounting accounts acquire acquired acquisition ... working world worth would year years yen yesterday yet york
0 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.000000 0.0 0.0 ... 0.0 0.0 0.0 0.026586 0.040825 0.000000 0.0 0.000000 0.0 0.352282
1 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.072832 0.0 0.0 ... 0.0 0.0 0.0 0.138419 0.000000 0.066417 0.0 0.000000 0.0 0.000000
2 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.000000 0.0 0.0 ... 0.0 0.0 0.0 0.000000 0.218928 0.000000 0.0 0.000000 0.0 0.000000
3 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.000000 0.0 0.0 ... 0.0 0.0 0.0 0.000000 0.000000 0.000000 0.0 0.100464 0.0 0.000000
4 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.000000 0.0 0.0 ... 0.0 0.0 0.0 0.000000 0.127352 0.000000 0.0 0.000000 0.0 0.000000
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
8466 0.0 0.0 0.0 0.0 0.181656 0.0 0.0 0.000000 0.0 0.0 ... 0.0 0.0 0.0 0.000000 0.000000 0.000000 0.0 0.000000 0.0 0.000000
8467 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.000000 0.0 0.0 ... 0.0 0.0 0.0 0.000000 0.000000 0.000000 0.0 0.000000 0.0 0.000000
8468 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.000000 0.0 0.0 ... 0.0 0.0 0.0 0.000000 0.000000 0.000000 0.0 0.000000 0.0 0.000000
8469 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.000000 0.0 0.0 ... 0.0 0.0 0.0 0.000000 0.055422 0.000000 0.0 0.000000 0.0 0.000000
8470 0.0 0.0 0.0 0.0 0.000000 0.0 0.0 0.000000 0.0 0.0 ... 0.0 0.0 0.0 0.000000 0.126124 0.000000 0.0 0.000000 0.0 0.000000

8471 rows × 953 columns

31.3. Illustrating t-SNE#

We use the texthero library here: https://spacy.io/universe/project/texthero

!pip install -U gensim --quiet
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 27.9/27.9 MB 67.4 MB/s eta 0:00:00
?25h
import random
news_sample = random.sample(list(df.Text),100)
news_sample
[' value line inc lt valu rd qtr jan shr cts vs cts net vs revs mln vs mln nine months shr dlrs vs cts net mln seven mln revs mln vs mln note periods include pretax investment income mln dlrs capital gains distributions mutual fund investment',
 ' salant lt qslt files reorganization plan salant corp said thomson co inc obion co inc subsidiaries filed joint reorganization plan u s bankruptcy court expect emerge chapter bankruptcy near future the company said hearing adequacy associated disclosure plan scheduled april nine completion plan subject approval creditors equity security holders bankruptcy court salant said reached agreement ray w williams continue president chief executive officer five years effective date reorganization plan substantially concluded talks new mln dlr unsecured credit effective date the company said committee unsecured creditgors committee equity security holders approved terms plan as previously announced creditors receive mln dlrs cash dlrs pct senior subordinated debentures four common shares dlrsd allowed unsecured claims salant today reported earnings year ended november dlrs dlr pretax provision loss sale subsidiary dlr post tax charge attributable costs expenses chapter settlement pre chapter claims well dlr tax credit a year lost dlrs dlr pretax provision plant closings',
 ' lt canadian satellite communications six mths net period ended february oper shr profit six cts vs loss cts oper profit vs loss revs vs note current shr net exclude tax gain dlrs five cts share full name lt canadian satellite communications inc',
 ' taiwan s second quarter imports seen rising taiwan imports second quarter expected rise billion u s dlrs billion year earlier billion first quarter year statistics department said a department official attributed increase growing domestic investment private public sectors it expected rise billion u s dlrs billion year earlier billion first quarter taiwan exports april june quarter expected rise billion u s dlrs billion year earlier billion first quarter the official said taiwan trade surplus expected climb billion u s dlrs second quarter billion year earlier it billion first quarter year most surplus expected come trade u s taiwan largest trading partner importer nearly pct taiwan total exports said he said expected taiwan imports including grains machinery power plant equipment u s to rise sharply government efforts balance trade washington he declined give figures',
 ' colombian oil exports not affected by quake colombian oil installations damaged earthquake shook ecuador southern colombia last night plans suspend exports spokesman state run oil company ecopetrol said he said damage reported unlike ecuador indefinite force majeure declared crude exports colombia currently produces barrels per day bpd crude exports january totalled bpd the quake colombia measured seven point international mercalli scale caused panic among residents injuries reported',
 ' exco buys u s government securities broker lt exco international plc subsidiary british commonwealth shipping co plc lt bcom l said agreed principle buy pct stake lt rmj holdings corp mln dlrs exco chairman richard lacy told reuters acquisition made bank new york co inc lt bk n currently holds pct rmj partners hold remainder bank new york partners retain pct stakes bought next six years rmj holding company rmj securities one largest u s government securities brokers it also involved broking notes obligations instruments sponsored u s federal agencies lacy said exco considering buying u s government securities broker past four years made offer rmj sold security pacific corp lt spc n rmj valued mln dlrs b c managing director peter goldie said rmj would bought multiple exco suggesting net income around mln dlrs the company earnings hit halving brokerage fees months ago volumes since doubled lacy said rmj employed people brokerage business lt sms unit provided computer software financial services community rmj securities offices new york total market turnover u s government securities billion dlrs day london billion it also given permission last week open office tokyo total market turnover lifted rapidly five billion dlrs day the acquisition would contribute five pct b c share earnings proforma basis',
 ' ico quotas before october unlikely delegates the restoration coffee export quotas end current coffee year oct sept seems unlikely given reluctance international coffee organization ico producers consumers resume negotiations interim quota accord producer delegates told reporters consumers producers see point reopening quota dialogue brazil position remains unchanged said brazil refusal accept reduction previous pct share ico global export quota effectively torpedoed talks last month aimed restoring quotas october delegates noted disappointment lack progress quotas forced coffee futures london new york new lows today traders said near may new york fell one dlr early trading around cents per pound traders said producer delegates said possibility reimposing quotas october remained ico agenda practice idea effectively discarded the ico executive board session week far barely touched quota debate demonstrating general unwillingness revive talks chances success still remote producer delegates said some producers hurry see quotas restored despite price collapse seen since failure last month negotiations said with brazil frost season approaching wants negotiate quotas one leading producer delegate said coffee prices normally rise brazil frost season mainly june august dealers roasters build stocks insurance possible severe frost damage brazil crop many producers interested working towards reimposing quotas october based new system quota allocations valid international coffee agreement expires said guatemala already proposed oilds producer group meet next two months begin talks allocate quota shares producers still seem divided overhaul quota distribution system producer delegates reporting growing support radical reallocation based principle objective criteria favoured consumers at last month council session splinter group small producers backed consumer demands new quota shares based exportable production stocks brazil colombia rest producers favoured leaving quota allocations unchanged except temporary adjustments a delegate one eight said producers supported cause the delegate said unless major producers like brazil showed readiness negotiate new quota shares prospects quota accord october also looked bleak the u s consumers still determined make reimposition quotas conditional redistribution quota shares based objective criteria ico observers remained sceptical brazil would prepared accept quota reduction ico council meets september brazil adopted tough stance banks external debt negotiations likely tough coffee said they said brazil reluctance open coffee export registrations might reflect fears would provoke another price slide force emergency ico council session would likely end failure producers met afternoon review market situation general discussion negotiations proceed producer delegate said producers plan hold consultations quotas may set date formal producer meeting plans fixed said the ico executive board reconvened hours local time hear report consultants ico operations the board meeting looks set end today day earlier scheduled delegates said',
 ' metropolitan financial lt mpc to acquire company metropolitan financial corp said signed agreement acquire stock closely held rothschild financial corp st paul minn details purchase withheld it said rothschild originated mln dlrs mortgage loans loan servicing portfolio stands billion dlrs officials companies estimated combined efforts could produce originations mln dlrs loan servicing portfolio well billion dlrs yearend',
 ' numac oil and gas ltd lt nmc year net oper shr cts vs cts oper net vs mln revs mln vs mln note cash flow mln dlrs cts shr vs mln dlrs dlrs shr net excludes ct shr loss discontinued operations gross proven probable reserves crude oil natural gas liquiids mln barrels pct year',
 ' computer memories lt cmin sets film firm merger computer memories inc ended disk drive operations june agreed acquire lt hemdale film corp transaction give hemdale owner control resulting company computer memories principal asset mln dlrs cash cash equivalents it agreed exchange newly issued shares equaling pct aggregate issued acquire hemdale that company owner john daly would become chief executive officer combined company would renamed hemdale film corp computer memories said proposed transaction subject results certain corporate reviews approval shareholders hold special meeting soon practicable the company said shares outstanding held intel corp lt intc it anticipated fintel shares purchased dlrs share connection merger hemdale computer memories said',
 ' brazilian bank workers decide on national strike brazilian bank workers voted launch nationwide strike month compounding labour unrest arising failure government anti inflation plan at rally city km northwest sao paulo bank workers voted strike march unless demand pct pay rises met wilson gomes de moura president national confederation groups bank employees unions representing workers told reuters indefinite stoppage would affect banks the vote came stoppage seamen entered third week oil workers threatened action state owned petroleum company petrobras',
 ' ccc sells farmers stock peanuts offers more the u s commodity credit corporation ccc sold short tons crop farmers stock peanuts domestic crushing u s agriculture department said the peanuts southwest area sold cts per lb total kernel content cts per lb department said the ccc offering additional peanuts sale later date department said',
 ' alc lt alcc anticipates st qtr profit alc communications corp said strong traffic growth cost reductions anticipates reporting profit first quarter versus loss mln dlrs cts share first quarter earlier company reported net tax loss mln dlrs dlrs share compared loss mln dlrs dlrs share',
 ' dollar general corp lt dolr th qtr net shr cts vs cts net vs revs mln vs mln year shr cts vs cts net vs mln revs mln vs mln',
 ' kdi lt kdi to buy triangle microwave lt trmw kdi corp said agreed principle acquire triangle microwave inc dlrs plus contingent payment triangle share it said holders contingent payment units entitled receive annual payments extent predepreciation gross profits triangle microwave years exceed threshholds ranging eight mln dlrs mln dlrs the company said holders triangle microwave options warrants entitled receive difference dlrs exercise price plus contingent payments kdi said completion transaction subject governmental approvals approval triangle microwave shareholders transaction valued mln dlrs it said shareholders triangle microwave controlling pct company stock agreed vote favor deal give kdi option buy shares certain components triangle microwave makes microwave components kdi diversified company produces electronic components technical products swimming pool equipment',
 ' combustion lt csp completes accuray lt acra buy combustion engineering inc said completed previously announced acquisition accuray corp merger trasaction closed friday dlrs per share',
 ' rio coffee trade prefers no pact to quota cut the failure talks introduce new coffee export quotas within international coffee agreement ica preferable alternative brazil sharply reduced quota proposed president rio de janeiro coffee trade association carlos calmon said he told reuters proposals reduce brazil quota pct world share pct present unacceptable country large stocks good harvest expected brazil capacity export mln bags year calmon added calmon said assuming mln bag global ica quota brazil share proposals would mln bags soluble would accounted mln leaving mln bags green coffee export it pity talks broke brazil better quota reduction added in brazil exported mln bags soluble green coffee including two mln bags non members a severe drought marketing problems cut exports last year mln bags calmon estimated stocks january mln bags mln already sold export the harvest year around mln bags added the latest brazilian coffee institute estimate last year harvest mln bags although many traders believe higher',
 ' dome petroleum reaffirms dome mines stake for sale at right price spokesman says',
 ' miller tabak has pct of penn traffic lt pnf lt miller tabak hirsch co said received accepted common shares penn traffic co response dlr per share tender offer expired friday together shares already owned pct penn traffic the company said penn traffic expected hold special shareholders meeting later month approve merger miller tabak tender price it said two miller tabak representatives named penn traffic board march four serve directors penn traffic president chief executive officer guido malacarne the company said received financing transaction first national bank minneapolis salomon inc lt sb',
 ' indian plant signs first alumina export contract an unnamed norwegian firm agreed buy tonnes alumina year refinery eastern orissa state due start operations next months commerce ministry official told reuters he said state owned national aluminium co owns plant state owned mineral metals trading corp signed first long term export agreement company gave details of plant tonnes annual capacity smelted tonnes aluminium remaining exported official said',
 ' canbra foods ltd year oper shr profit dlrs vs loss cts',
 ' saudi success seen in curbing opec production saudi arabia succeed pressuring members organization petroleum exporting countries stay within production quotas said morgan stanley group managing director john wellemeyer wellemeyer speaking reporters offshore oil engineering conference also said expected opec nations attempt hold prices dlrs barrel several years keep industrial demand residual fuel oil strong over next weeks i think see concerted effort saudis get production wellemeyer said the saudis committed price level dlrs barrel willing make happen said in recent weeks oil prices fell dlrs barrel level market reports ope members producing quota pushing total opec production mln barrels per day but prices rebounded today april u s crude prices one dlr dlrs barrel belief saudi arabia attempting curb opec output wellemeyer said sharp declines u s oil production could push demand opec oil mln barrels per day early mln barrels per day although projected increases demand opec oil strengthen world prices wellemeyer said believed organization would hold official price dlrs barrel time prevent residual fuel users switching natural gas supplies the interfuel swing market accounts eight mln barrels day pct world demand oil',
 ' brazilian red meat output down sharply usda brazilian red meat production fell pct mln tonnes due drought reduced slaughter weight herd rebuilding started high cattle prices u s agriculture department said in report world production trade developments usda said beef production expected reach mln tonnes pork production rose pct mln tonnes due sharp rise beef prices expected remain level year usda said',
 ' malta tenders for white sugar today trade malta tendering buy tonnes white sugar today arrival two equal parts may june traders said',
 ' ultramar net loss mln stg vs mln profit',
 ' india reduces export duty on coffee india cut export duty coffee rupees per kg rupees effective march coffee board official said the reduction help india reach coffee export target tonnes fiscal ending march provisionally estimated exports tonnes actual tonnes said india likely press international export quotas meeting coffee producers london week depressed prices added the international coffee organisation represents consumers producers far failed reach agreement quotas india feels useful quotas slide prices unlikely halted immediately said export quotas suspended february market prices surged drought devastated brazil coffee crop',
 ' oil prices said now based on futures price energy futures set standard oil pricing said arnold safer president the energy futures group inc consulting firm petroleum futures trading new york mercantile exchange literally set spot market prices u s said adding oil products sellers offer contracts based daily average nymex prices he also said petroleum futures major market oil companies well commodity traders his remarks made national petroleum refiners association',
 ' murray ohio lt myo sees higher st qtr earnings the murray ohio manufacturing co said expects first quarter earnings higher dlrs dlrs per share recorded first quarter last year the company produces lawn mowers bicycles said earnings ahead last year due increased lawn garden shipments january february record setting pace march',
 ' federal express corp lt fdx rd qtr feb net oper shr cts vs cts oper net mln vs mln revs mln vs mln avg shrs mln vs mln nine mths oper shr dlrs vs dlrs oper net mln vs mln revs billion vs billion avg shrs mln vs mln note net excludes losses discontinued operations nil vs mln dlrs quarter mln dlrs vs mln dlrs nine mths quarter net includes gains sale aircraft two mln dlrs vs dlrs',
 ' interactive technologies inc lt itxi st qtr net shr nine cts vs eight cts net vs sales vs avg shrs vs note periods end january respectively',
 ' stuarts department stores lt stus th qtr net ended jan shr one ct vs cts net vs revs mln vs mln year shr cts vs cts net vs revs mln vs mln note full name stuarts department stores inc',
 ' ibc registers mln bags of export sales the brazilian coffee institute today registered mln kilo bags green coffee may shipment ibc statement said this brings total two days registrations open mln including bags soluble today registrations comprised bags members non members international coffee organisation no soluble sales registered today',
 ' irving trust lt v raises prime rate irving trust co said raising prime rate pct effective immediately it becomes fourth u s bank raise rate following citibank chase manhattan manufacturers hanover trust',
 ' usda estimates australia wheat crop the u s agriculture department forecast australia wheat crop mln tonnes vs mln tonnes last month it estimated output mln tonnes vs mln last month australian wheat exports forecast mln tonnes vs mln tonnes last month exports estimated mln tonnes vs mln last month',
 ' southwestern energy lt swn arkla lt alg set pact southwestern energy co said reached agreement arkla energy resources arkla carry gas owned southwestern subsidiaries under agreement interstate pipeline division arkla inc carry mln cubic feet gas day dec subject capacity mln cubic feet day mln feet day rest pact payment terms vary depending type service provided southwestern spokesman said the deal effective march one expires july one renewable yearly thereafter said the pact calls transmission gas owned arkansas western gas co seeco inc arkansas gas gathering co southwestern energy production co southwestern energy said',
 ' bhp net seen around mln dlrs for nine months australia largest company the broken hill pty co ltd lt brkn s bhp expected report net profit around mln mln dlrs tomorrow first nine months ended february share analysts polled reuters said this would well mln dlrs earned first three quarters in full year ended may group earned record mln dlrs the analysts estimated group would report third quarter net region mln mln dlrs mln year earlier mln second quarter bhp earnings first half ended november amounted mln dlrs sharply mln year earlier the analysts predicted bhp report upturn petroleum earnings compared first quarter reflecting improvement crude oil prices bass strait fields gains would offset lower mineral steel earnings they said mineral group hit lower coal prices shipments japan steel division affected industrial production problems the analysts noted third quarter normally bhp lowest earning period owing number seasonal factors predicted sharp rise fourth quarter net around mln dlrs one key factor fourth quarter expected tax break mln dlrs investment allowance capital expenditure steel division said they said saw bhp full year earnings around mln mln dlrs they added decline would surprise noting bhp said would difficult equal record net profit',
 ' u s exporters report tonnes corn switched from unknown to ussr for',
 ' citizens growth lt citgs omits quarterly dividend citizens growth properties said ommitted regular quartelry dividend result decreased earnings principally attributable default borrower trust laargest mortgage loan the trust last paid cts january the trust said also reaffirmed limited share repurchase program subject available cash flow light defaulted mortgage',
 ' sosnoff starts bid for caesars world lt caw lt mts acquisition corp company formed martin t sosnoff said started tender offer shares caesars world inc dlrs in newspaper advertisement mts said offer withdrawal rights expire april three unless extended sosnoff new york investor already owns four mln caesars mln shares outstanding pct caesars largest shareholder caesars owns casino hotels nevada honeymoon resorts pennsylvania pocono mountains it also controls caesars new jersey inc lt cjn owns atlantic city n j casino hotel for second quarter ended january caesars world earned mln dlrs revenues mln dlrs earnings dlrs revenues mln dlrs year for fiscal company earned mln dlrs revenues mln dlrs mts said offer conditioned receipt least enough shares give sosnoff majority interest fully diluted basis arrangement sufficient financing buy caesars shares already owned pay related costs approval new jersey casino control commission nevada gaming commission state gaming control board mts said marine midland banks inc lt mm committed lend mln dlrs acquisition use best efforts syndicate another mln dlrs senior financing transaction it said financial adviser painewebber group inc lt pwj stated writing subject market conditions highly confident arrange commitments mln dlrs mezzanine financing mts said expect problems obtaining new jersey nevada regulatory approval acquisition since ownership caesars stake already cleared in june sosnoff requested seat caesars world board request yet granted in september sosnoff chairman lt atalanta sosnoff capital corp filed clearance u s antitrust laws raise interest caesars world pct sosnoff said letter caesars world chairman chief executive officer henry gluck the decision go directly shareholders made urging may financial legal advisors repeatedly stressed lack responsiveness management past sosnoff said made numerous efforts express views management ways maximizing shareholder values said caesars twicce refused request board seat my advisers felt i given advance notice would used time throw obstacles offer rather giving serious consideration said sosnoff said hopes caesars world management willing negotiate acquisition agreement as i indicated publicly past i believe operating management company performed well appropriate consideration given significant equity interest company following acquisition sosnoff said letter gluck mts said sosnoff asked company fix march record date determination shareholders entitled authorize action without meeting including election removal directors',
 ' mark iv lt iv starts bid for conrac lt cax mark iv industries inc said started dlr per share tender offer shares conrac corp announced yesterday afternoon in newspaper advertisement company said offer withdrawal rights expire april unless extended the offer conditioned receipt minimum number shares conditioned arrangement financing mark iv already owns pct conrac mln shares outstanding',
 ' curtice burns foods inc lt cbi raises payout qtly div cts vs cts prior pay april record april',
 ' german march cost living pct year ago feb pct official',
 ' yeutter sees u s japan verging on trade conflict the united states japan brink serious conflict trade especially semiconductors japanese unwillingness public bodies buy u s super computers barriers u s firms seeking participate eight billion dlr kansai airport project u s trade representative clayton yeutter said he talking reporters yesterday eve two day meeting trade ministers review progress made committees set uruguay meeting last september launched new round gatt general agreement tariffs trade talks european community ec commissioner willy de clercq meanwhile told reporters conflict world three major trading economic powers ec u s and japan set poor example members gatt australian trade minister john dawkins told reporters bilateral retaliation enormous expense rest world way solve trade disputes new zealand trade minister mike moore told colleagues great progress made preparing current round gatt negotiations must sidetracked the ministers said want maintain momentum towards fresh negotiations avert serious trade conflicts yeutter said problem international trade talks tended get bogged years countries get serious negotiating end day maybe five six years future he also said consider new u s congress protectionist months ago that healthy development added if asked year months ago i would said terribly protectionist members congress contemplative members congress begun realise protectionism answer billion dlr trade deficit yeutter said they also begun realise legislate solutions billion dollar trade deficit realistic judgement responsible issue months ago he added whether reflected legislation eventually emerges another matter',
 ' u s soy producers think ec oils tax unlikely american soybean producers confident proposed european community ec tax vegetable oils fats rejected leaving nothing chance american soybean association asa president elect wayne bennett said bennett leading one three soybean producer delegations lobbying tour ec capitals speaking lunch after meetings economics foreign ministries morning said dutch government indicated would vote proposal number countries our information suggests required number votes brussels prevent tax proposal going forward said the proposal talked brussels past years dropped every time what want kill bennett added backing soybean producers active lobbying u s government also indicated prepared retaliate penal import taxes proposal get said the u s government also feels good case fight proposed tax general agreement tariffs trade gatt u s embassy spokesman said u s exports soybeans products ec account one fifth annual production worth billion dlrs year bennett said the proposed tax oils fats would hit u s producers badly time virtually doubling price soyoil ec would suffer far worse higher priced oils nature proposed tax added the revenue ec tax would simply used finance ec oilseed subsidy machine said we asa dedicated free traders we helped defeat wine equity act two years ago stand watch farmers suffer protectionist ec measures bennett said the mood u s is turning increasingly protectionist ec actions fueling chances trade war added',
 ' bogart crafts corp lt vogt year loss yr ends nov shr loss cts vs loss dlrs net loss vs loss revs mln vs mln note prior yr ended nov',
 ' supermarkets general lt sgl gets unsolicited bid supermarkets general corp said received unsolicited proposal third party acquire company dlrs per share cash supermarkets also said retained shearson lehman brothers inc advise board directors proposal supermarkets general currently mln shares outstanding its stock currently trading new york stock exchange the woodbridge n j supermarket operator supermarkets specialty retail stores convenience food stores drug stores for nine months ended november supermarkets reported net income mln dlrs',
 ' towle manufacturing co lt qtow th qtr oper loss oper shr loss dlrs vs loss dlrs oper net loss mln vs loss mln revs mln vs mln year oper shr loss dlrs vs loss dlrs oper net loss mln vs loss mln revs mln vs mln avg shrs vs note current year excludes gain mln dlrs disposal discontinued operations shr figures preferred dividend requirements',
 ' lincoln national corp lt lnc sets quarterly qtly div cts vs cts prior pay may one record april',
 ' india buys rbd palm olein at tender the indian state trading corp bought one possibly two tonne cargoes malaysian refined bleached deodorised palm olein vegetable oil import tender today mar apr shipment dlrs per tonne cif traders said',
 ' thermo process lt tpsi completes acqusition thermo process systems inc said completed purchase thermo process services inc subsidiary thermo electron corp lt tmo thermo process systems said issued shares common stock thermo electron connection sale',
 ' ford motor co of canada ltd th qtr shr dlrs vs cts',
 ' centerior energy corp lt cx sets quarterly qtly div cts vs cts prior pay may record april',
 ' lotus lt lots to acquire lt computer access corp lotus development corp said signed letter intent acquire substantially assets computer access corp undisclosed terms computer asscess makes bluefish full text search retrieval software international business machines corp lt ibm compatible personal computers the company said acquisition subject approval boards',
 ' fed s heller says dollar s current level is appropriate',
 ' japan cabinet approves bill on gold coin issues the cabinet approved bill making easier government issue commemorative coins finance ministry official said the bill must still approved parliament would take effect april it would allow government issue yen coins without special legislation although higher valued coins would still need special law official said at present issue coins yen less',
 ' eastman kodak lt ek to sell holdings eastman kodak co said plans sell pct holding icn pharmaceuticals lt icn part nine pct holdings viratek lt vira it said purpose investments lay groundwork creation nucleic acid research institute since achieved longer reason maintain equity positions kodak said kodak holds sahres icn currently trading viratek trading',
 ' j p morgan says brazil action will reduce first quarter net by about mln dlrs',
 ' shell canada schedules annual refinery shutdown shell canada ltd pct owned royal dutch shell group lt rd lt st scheduled annual maintenance refinery shutdowns next two months company spokeswoman judy wish said wish said refineries stockpile production shutdowns maintain normal supply maintenance carried production shell major refinery strathcona alberta closed one month wish said there layoffs associated refinery maintenance added',
 ' keating revises down australian growth forecast treasurer paul keating forecast economic growth slightly two pct financial year ending june year pct forecast contained budget delivered last august australia terms trade also fell pct past two years told parliament terms trade difference import export price indexes despite figures budget forecast pct annual growth employment would met keating said unemployment currently pct workforce this government dragging australia trading holocaust kind seen since second world war keating said we pushing place recession we holding gains unemployment bringing unemployment said adding government help country avoid recession',
 ' business computer lt bcsi had th quarter profit business computer solutions inc said expects report profit fourth quarter ended february first quarterly profit ever dlrs revenues dlrs a year lost dlrs sales dlrs the company attributed improved results increased purchases zfour language development environment computer software business computer said expects report full year loss dlrs sales dlrs last year lost dlrs revenues dlrs',
 ' corrected university patents inc lt upt nd qtr qtr ends jan oper shr loss cts vs loss cts oper loss vs loss revs vs six mths oper shr loss cts vs loss cts oper loss vs loss revs vs note prior year excludes losses discontinued operations cts per share quarter cts per share year corrects march item show losses instead profits also corrects quarter loss discontinued operations',
 ' lt bedford computer corp year net shr given net profit vs loss sales vs note company operating chapter bankruptcy sales exclude contract revenues dlrs net includes reversal dlrs reserves longer deemed necessary tax credit dlrs',
 ' lt dylex ltd year jan net shr cts vs one dlr net mln vs mln sales billion vs billion note excludes extraordinary gain mln dlrs two cts per share public issue affiliate shares',
 ' u s m falls mln dlrs in march week feb m down billion m up billion',
 ' german february central bank money grows annual pct january prov bundesbank data',
 ' kentucky smelters get relief on higher rates owners two aluminum smelters kentucky received temporary relief higher electric rates decision tuesday state regulators denying rate hike big rivers electric corp henderson ky but owners smelters national southwire aluminum co alcan aluminium ltd lt al said viability operations would depend part upon rate case eventually settled we hoping rate increases say sure it still possible close smelter national southwire spokesman said he said variables consider decision whether close continue smelter located hawesville miles west louisville national southwire owned national intergroup inc lt nii holds pct southwire co holds rest spokesman said a spokesman montreal based alcan said the decision pages long legal ese certainly long time make decision means sebree smelter henderson miles west louisville but delighted big rivers electric denied requested rate increase a spokesman utility cooperative generates wholesales electricity four distributors said requested increase mln dlrs year rates the kentucky public service commission denying increase asked utility meet creditors include manufacturers hanover corp lt mhc irving bank corp lt v smelters renegotiate rate plan utility spokesman said the commission suggested big rivers electric work flexible rate schedule smelters would index electric costs price aluminum said we always amenable try far assure two aluminum smelters remain viable said no meetings scheduled none planned utility creditors aluminum plant owners the commission set hearing rate issue july',
 ' bally lt bly completes purchase of golden nugget bally manufacturing corp said completed acquisition golden nugget casino hotel atlantic city new jersey golden nugget inc bally also acquired golden nugget various parcels real estate atlantic city noted the transaction included mln dlrs cash stock assumption mln dlrs mortgage',
 ' lt devtek corp nd qtr jan net shr cts vs nine cts net vs revs mln vs mln six mths shr cts vs cts net vs revs mln vs mln',
 ' whittaker corp st qtr oper shr cts vs cts',
 ' realty south investors inc lt rsi year net shr dlrs vs cts net vs revs vs investments mln vs mln note shr figures adjusted split feb results reflect operations eight months ended dec company began operating may',
 ' australian government to pay subsidies usda the australian government likely reimburse australian wheat board awb mln u s dlrs pay wheat farmers crop u s agriculture department said in report export markets u s grains department said sharp fall world wheat prices reduced export sales revenue awb levels insufficient cover breakeven export price estimated around dlrs per tonne for example recent large sales wheat china mln tonnes egypt mln tonnes well breakeven export price said australian wheat farmers normally receive advance payment known guaranteed minimum price gmp calculated pct average estimated returns current year two lowest previous three years department said in addition deductions taxes freight handling storage deducted gmp farmer receives but department said australian bureau agricultural economics bae predicts wheat production drop sharply mln tonnes mln the decline result low world grain prices leading shifts livestock crops could benefit u s wheat exports department said',
 ' amcast industrial corp lt acst nd qtr net qtr ends march one shr profit cts vs loss cts net profit vs loss mln revs mln vs mln avg shrs vs six mths shr profit cts vs loss net profit vs loss mln revs mln vs mln avg shrs vs note figures qtr year prior include pre tax restructuring charge mln',
 ' slough estates views prospects confidently slough estates plc lt slou l said views prospects confidence in statement accompanying results reported rise mln stg pretax profit mln stg said signs existing threat excess supply may lessened there also return interest industrial investment an external appraisal group investment properties carried last year found gross value mln stg dec',
 ' packaging systems lt paks to buy label firm packaging systems corp said agreed acquire lt walter richter labels inc privately held maker woven labels based paterson n j terms acquisition expected completed within days disclosed',
 ' northern telecom ltd lt nt declares stock split two one stock split pay may note split subject approval shareholders april annual meeting company also said increase dividend post split shares six cts five cts',
 ' idb communications group inc lt idbx year net period ended december shr cts vs cts net vs revs vs',
 ' ec oils tax canada corn ruling opposed by panel the u s senate finance committee approved nonbinding resolutions urging reagan administration oppose canada ruling u s corn imports proposed new european community tax vegetable oils the resolutions approved voice vote sent senate floor expected approved the ec oils measure offered sen john danforth r mo urges administration take strong retaliatory measures tax approved ec council ministers sen david durenberger r minn offered corn amendment urges administration file complaint gatt u s believes corn decision canada unjustified canada recently imposed permanent duty cents per bushel u s corn imports',
 ' olivetti does not exclude stake in sgs thomson ing c olivetti ec spa lt oliv m exclude possibility investing semiconductor venture currently discussion italy lt stet societa finanziaria telefonica p a france thomson csf lt tcsf pa olivetti spokesman said he said olivetti approached two partners involved financial conditions proposal considered interesting company exclude possibility investing venture however olivetti made decision investment disposal information evaluate move stet thomson said last thursday negotiating accord involving respective subsidiaries lt sgs microelettronica spa lt thomson semiconducteurs civil semiconductor field they said accord concluded would put approval french italian authorities the olivetti spokesman responding reuters query italian press reports today saying olivetti might participate venture two pct stake',
 ' india and japan to discuss iron ore prices the state owned minerals metals trading corp send team japan next week negotiate iron ore export contract beginning april trade sources said japan biggest buyer indian iron ore imports around mln tonnes year asked india reduce prices current average dlrs tonne sources said japan said may forced reduce ore imports india next year new delhi fails reduce price one source said declined give details',
 ' american travellers lt atvc to make acquisition american travellers corp said entered agreement purchase isl life insurance co dallas corporate shell active licenses operate states dlrs the company said closing expected late spring result american travellers licensed seven new states',
 ' minstar inc said it sold all mln of its borg warner shares',
 ' ivory coast minister delayed for cocoa talks ivorian agriculture minister denis bra kanon chairman international cocoa organization icco council able open council session tomorrow ivorian icco delegate told reuters he arrive sometime later meetings delegate said the council session chaired instead icco vice chairman sir denis henry delegate grenada icco officials said ivorian officials last week said bra kanon due return home funeral ceremonies sister ivorian president felix houphouet boigny march',
 ' german february industrial output rises pct january fall pct official',
 ' u s bank discount borrowings mln dlrs u s bank discount window borrowings less extended credits averaged mln dlrs week wednesday march federal reserve said total borrowings week rose mln dlrs mln dlrs extended credits three mln dlrs mln dlrs the week first half two week statement period net borrowing prior week averaged mln dlrs commenting two week statement period ended march fed estimated banks daily average net free reserves mln dlrs rather mln dlrs first reported a fed spokesman told press briefing large single day net misses fed reserve projections first week latest bank statement period none large money center banks borrowed discount window week wednesday borrowing made smallest banks for week whole borrowing split roughly evenly large regionals small banks natural float ranged low near zero thursday fed spokesman could give particular reason high nearly mln dlrs tuesday the tuesday peak included mln dlrs transportation float mid south atlantic states noting weather basically good march spokesman said transportation float averaged mln dlrs day full week float related ofs negative mln dlrs wenesday due number unrelated cash letter error corrections five districts as ofs peaked mln dlrs tuesday',
 ' iranian oil minister in uae talks iranian oil minister gholamreza aqazadeh united arab emirates uae discuss oil prices general market situation iranian officials accompanying said he meet uae president sheikh zaid bin sultan al nahayan oil minister mana said al oteiba aqazadeh arrived last night brief stopover riyadh met saudi arabia oil minister hisham nazir the official saudi press agency quoted saying talks riyadh nazir constructive good aqazadeh said organisation petroleum exporting countries opec members agreed holding production stable reiterated importance maintaining oil prices opec members agreed december limit production mln barrels per day first half year benchmark price dlrs barrel february aqazadeh also visted opec members gabon algeria libya the iranian news agency irna quoted saying leaving tripoli opec everything possible make oil prices permanently stable',
 ' lower ascs corn prices to affect ten states the agriculture department widening louisiana gulf differentials affect county posted prices number two yellow corn ten states usda official said all counties iowa affected counties use gulf price corn illinois indiana tennessee kentucky missouri mississippi arkansas alabama louisiana said ron burgess deputy director commodity operations division usda usda last night notified grain industry effective immediately gulf differentials used price interior corn would widened sliding scale basis four eight cts depending differential usda action taken lower excessively high posted county prices corn caused high gulf prices we following louisiana gulf situation month think going get back line nearby time burgess said burgess said usda probably narrow back gulf differentials gulf prices recede if mark high much mark low said while forecasting adjustments gulf prices fall burgess said changes usda price system planned right we tinker we make changes lightly make changes often said',
 ' cpc international inc lt cpc regular dividend qtly div cts vs cts prior pay april record march',
 ' kelly oil and gas partners lt kly year dec shr cts vs cts net mln vs mln revs mln vs mln',
 ' wickes lt wix plans reverse split calls debt wickes cos inc said board authorized one five reverse stock split plans call company pct senior subordianted debentures due the company said seek shareholder approval reverse stock split annual shareholders meeting scheduled june at january wickes mln shares outstanding company also said wickes also said call debentures dec assuming market conditions remain essentially',
 ' bundesbank buys dollars in frankfurt dealers the bundesbank bought large amounts dollars yen apparent attempt hold dollar yen dealers said the dollar intervention concert central banks said dealers said bank japan bank england supported dollar yen earlier today two banks u s federal reserve also active yesterday the bundesbank declined comment dealers remarks dealers said intervention underlined determination central banks keep currencies within recent ranges following last month agreement paris six leading countries foster currency stability one dealer said repeatedly contact bundesbank morning see wanted buy dollars japanese u k central bank moves he said bundesbank told observing situation see intervene consultation central banks since paris agreement february dollar yesterday traded mark range yen traders reluctant push dollar test central banks resolve defend currency stability but test came week dollar falling marks yen dealers said reviving trade dispute washington tokyo growing sentiment dollar would fall narrow obstinate u s trade deficit behind weakness this week intervention showed central banks prepared cooperate defend paris pact dealers said dealers said significant west german british central banks supporting dollar yen that showed pact involved multilateral cooperation central banks foster currency stability said but unclear cooperation arranged frequent consultations central banks',
 ' hungary hopes devaluation will end trade deficit national bank hungary first vice president janos fekete said hoped planned eight pct devaluation forint spur exports redress last year severe trade deficit west fekete told reuters interview hungary must achieve least equilibrium hard currency trade it useful devaluation said there real push exports bit curb imports the official news agency mti said today hungary would devalue eight pct expected new rates announced later today fekete said rates would come effect tomorrow he said one reason devaluation hungary higher rate inflation past two years main partners around eight pct five pct this partly effect action hungary took prevent inflation soaring oil price shocks added hungary devalued similar amount last september three four pct early last year but country hard currency trade balance nevertheless fell deficit mln dlrs surplus mln billion fekete said hungary hoping hard currency trade surplus mln dlrs year likely outcome would closer equilibrium total hard currency trade around billion dlrs one western commercial attache said devaluation change anything it useful also make efforts restructure industry improve quality export goods fekete said hoped raise credits good terms year invest restructuring industry it would role persuade international banks cooperate process he noted hungary given aa rating enabling raise money japanese samurai bond market hungary net hard currency debt soared billion dlrs last year billion partly current account deficit billion dlrs partly fall dollar increased dollar value debt denominated marks yen he said feared net debt would also rise slightly year favour borrowing purpose modernisation i credits invest purpose said i credits consumption he forecast gross domestic product growth two pct year one pct fekete said hungary would continue restructure debt profile prepaying high interest shorter medium term loans cheaper long term money looking fixed interest rate bond market considered rates low hard currency foreign exchange reserves would stay around billion dlrs said on budget deficit tripled provisional billion forints last year quadrupling fekete said finance ministry working measures reduce approved target deficit year billion forints billion forints',
 ' ford lt f nears gm lt gm in executive bonuses ford motor co neared general motors corp last year executive bonuses topped larger automaker profit sharing payments workers ford outstripped gm earnings last year said incentive bonuses totaled mln dlrs slightly behind general motors mln general motors however make profit sharing payments workers ford made profit sharing distribution mln dlrs dlrs per worker general motors saw earnings drop billion dlrs billion said profit sufficient generate payout profit sharing formula ford earned billion dlrs billion said recognizes employees efforts fulfills commitment many ways including profit sharing',
 ' united biscuits lt ubis l weeks to january shr p vs p div p vs p making p vs p turnover billion stg vs billion pretax profit mln vs mln tax mln vs mln trading profit mln vs mln trading profit includes ub foods europe mln vs mln ub restaurants mln vs ub foods u s mln vs mln other mln vs mln unallocated costs mln vs mln interest mln vs mln note full name company united biscuits holdings plc minority interests mln vs extraordinary charges mln vs mln extraordinary charges credits include surplus bid imperial group plc mln vs nil costs philadelphia bakery closure nil vs mln',
 ' dollar seen falling unless japan spurs economy underlying dollar sentiment bearish operators may push currency new low unless japan takes steps stimulate economy pledged paris accord foreign exchange analysts polled reuters said the dollar expected try psychological barrier yen fall even level senior dealer one leading bank said the dollar eased week remains stable around yen six major industrial countries agreed meeting paris february foster currency stability some dealers said dollar may decline long term drastic fall unlikely u s fears renewed inflation fears reduced japanese purchases u s treasury securities needed finance u s deficit dealers generally doubted whether economic package japan could adopt soon would effective enough reduce trade surplus significantly said measures would probably invite u s steps weaken dollar under paris accord tokyo promised package measures fiscal budget passed boost domestic demand increase imports cut trade surplus but debate budget delayed opposition boycott parliamentary business proposed imposition five pct sales tax government slim chance producing meaningful economic package near future dealers said if steps taken protectionist sentiment u s congress grow putting greater downward pressure dollar said the factors affecting u s currency changed since paris accord added underlying sentiment dollar remains bearish due still sluggish u s economic outlook international debt crisis triggered brazil unilateral suspension interest payments foreign debts reduced clout reagan administration result iran contra arms scandal said senior dealer leading trust bank there possibility dollar may decline around yen end year said chemical bank tokyo branch vice president yukuo takahashi but operators find hard push dollar either way fear possible concerted central bank intervention dealers said widespread rumours u s federal reserve telephoned banks new york ask quotes last wednesday even intervened sell dollar rose marks the bank england also apparently sold sterling london neared dlrs wednesday said but dealers said doubted efficacy central bank intervention saying may stimulate dollar decline many dealers likely await dollar buying intervention chance sell dollars however first national bank chicago tokyo branch assistant manager hiroshi mochizuki said the dollar show drastic movement least end march other dealers said u s seems unwilling see strong dollar swing japanese companies close books fiscal year ending march weak dollar would give japanese institutional investors paper losses foreign holdings could make lose interest purchases u s treasury securities u s monetary officials may refrain making comments month avoid influencing rates said',
 ' allegheny lt ai sued over proposed buyout allegheny international inc said first boston inc lt fbc sunter holdings corp subsidiary named defendants class action filed court common pleas allegheny county pa seeks injunction allegheny proposed merger sunter the company said board former directors first boston also named defendants it said sunter intend vigorously oppose action allegheny said class action suit alleges price paid transaction grossly unfair the company said suit allegations similar contained earlier federal court suit',
 ' cross and trecker lt ctco to sell unit cross trecker corp said warner swasey subsidiary seek sell grinding division focus areas business the company said grinding division sales last year mln dlrs it makes grinding machines',
 ' mark iv corrects agreement with baird lt batm mark iv industries inc lt iv said may consider bid seek control baird corp said baird agreed hold defensive measures without giving mark iv least hours notice in filing securities exchange commission mark iv corrected statement made yesterday another sec filing listed several agreements reached baird including baird would take anti takeover steps without providing least hours notice mark iv said later told baird baird given assurance',
 ' diamond shamrock dia cuts crude prices diamond shamrock corp said effective today cut contract prices crude oil dlrs barrel the reduction brings posted price west texas intermediate dlrs barrel copany said the price reduction today made light falling oil product prices weak crude oil market company spokeswoman said diamond latest line u s oil companies cut contract posted prices last two days citing weak oil markets',
 ' bank of france sets money market tender the bank france said invited offers first category paper today money market intervention tender money market dealers said conditions seemed right bank cut intervention rate tender quarter percentage point pct eight reflecting easing call money rate last week french franc steadiness foreign exchange markets since february currency stabilisation accord group five canada intervention rate last raised eight pct january call money today quoted pct',
 ' wickes cos inc th qtr shr loss two cts vs profit cts']
import gensim, logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

#Tokenize each document
def textTokenize(text_array):
    textTokens = []
    for h in text_array:
        textTokens.append(h.split(' '))
    return textTokens

sentences = textTokenize(news_sample)

#Train the model on Word2Vec
model = gensim.models.Word2Vec(sentences, min_count=1)
%%time
from sklearn.manifold import TSNE

# X = model.wv[model.wv.key_to_index]
# labels = model.wv.index_to_key

X = model.wv.vectors
labels = model.wv.index_to_key

figure(figsize=(20,10))

tsne = TSNE(n_components=2)
X_tsne = tsne.fit_transform(X)
x = X_tsne[:, 0]
y = X_tsne[:, 1]

scatter(x,y)
for i, txt in enumerate(labels):
    annotate(txt, (x[i], y[i]))
show()
_images/91a7c224c8ca57553da98a7ee94fcc2215f5c0403f423174e460f13b042bb9bc.png
CPU times: user 36.1 s, sys: 297 ms, total: 36.4 s
Wall time: 45 s

31.4. UMAP#

Recently, there is an improvement on t-SNE, called UMAP, coming from the Biology and Life Sciences, see: https://arxiv.org/abs/1802.03426

UMAP extends to any dimensional enbedding, replaces the perplexity requirement with a nearest-neighbors one (see the top of page 15 here: https://arxiv.org/pdf/1802.03426.pdf, and is faster in run time.

31.5. Let’s use TextHero#

https://texthero.org/

TextHero’s text cleaning function does the following cleanups:

  1. Fills in empty space for na values

  2. lowercase text

  3. removes digits

  4. removes punctuation

  5. remove stopwords

  6. removes whitespace

  7. removes accents on words (also known as “diacritics”)

# !pip install unidecode
# !pip install gensim==4.2.0
# !pip install texthero==1.0.4

Sadly, texthero has not been maintained or updated since 2021, and has many conflicts with other active libraries, in particular pandas. The installs above may be useful but need a lot of work to get working, so I have deprecated it for now in these notes.