I read that using the Coherence measure can help estimate the most optimal number of topics (K) to be used in the LDA model. I created the below code to run multiple LDA Models with different numbers of topics and calculate the Coherence measure for each.
def compute_coherence_values(dictionary,corpus,texts,limit,start=2,step=1):
coherence_values = []
model_list = []
for num_topics in range(start, limit, step):
model = gensim.models.ldamodel.LdaModel(corpus=corpus, num_topics=num_topics,random_state=100,
chunksize=200,passes=10,per_word_topics=True,id2word=id2word)
model_list.append(model)
coherencemodel = CoherenceModel(model=model, texts=texts, dictionary=dictionary, coherence='c_v')
coherence_values.append(coherencemodel.get_coherence())
return model_list, coherence_values
model_list, coherence_values = compute_coherence_values(dictionary=id2word,corpus=corpus,
texts=data_lemmatized, start=2, limit=500, step=5)
# Show Coherence graph
limit=500; start=2; step=5;
x= range(start, limit, step)
plt.plot(x, coherence_values)
plt.xlabel("Num Topics")
plt.ylabel("Coherence score")
plt.legend(("coherence_values"), loc='best')
plt.show()
Now, according to this graph, the coherence measure peaks at for example 150, 187, 200, and above!
I do not quite understand how the coherence doesn't go down when
using too much number of topics? Why does it plateau?
When Running my LDA using any of the above-mentioned numbers of topics, I get the same topic name applied to all extracted topics with 0% relevance of each word!
Am I doing something wrong here?
Sample of output:
[(149, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (103, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (49, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (40, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (56, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (105, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (35, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (63, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (146, '0.288*"role" + 0.135*"machine" + 0.119*"age"'), (120, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (18, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (92, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (157, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (143, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (39, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (141, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (78, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (151, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (90, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"'), (101, '0.000*"klebsiella" + 0.000*"cyclade" + 0.000*"slope"')]
If I choose topic numbers <100 I ok results:
[(132, '0.263*"subject" + 0.155*"deputy" + 0.091*"plastic"'), (110, '0.208*"club" + 0.164*"fan" + 0.096*"ground"'), (200, '0.225*"book" + 0.080*"writer" + 0.078*"winner"'), (16, '0.000*"cellnet" + 0.000*"katherine" + 0.000*"accommodation"'), (71, '0.000*"cellnet" + 0.000*"katherine" + 0.000*"accommodation"'), (29, '0.543*"language" + 0.095*"rush" + 0.074*"hip"'), (66, '0.312*"case" + 0.195*"court" + 0.129*"charge"'), (34, '0.000*"cellnet" + 0.000*"katherine" + 0.000*"accommodation"'), (191, '0.492*"film" + 0.146*"cinema" + 0.094*"director"'), (28, '0.295*"number" + 0.132*"chart" + 0.107*"week"'), (116, '0.130*"email" + 0.109*"union" + 0.086*"difference"'), (144, '0.283*"rate" + 0.253*"interest" + 0.036*"month"'), (207, '0.202*"camera" + 0.107*"message" + 0.058*"text"'), (174, '0.260*"revenue" + 0.188*"earning" + 0.104*"world"'), (121, '0.631*"distribution" + 0.000*"accommodation" + 0.000*"cambridgeshire"'), (68, '0.382*"price" + 0.179*"oil" + 0.095*"demand"'), (163, '0.417*"action" + 0.258*"official" + 0.095*"lawsuit"'), (206, '0.135*"race" + 0.111*"world" + 0.066*"year"'), (215, '0.305*"technology" + 0.194*"device" + 0.085*"generation"'), (125, '0.312*"man" + 0.072*"hunt" + 0.069*"ban"')]
N.B: The corpus is made up of 10k unique documents
My program runs successfully and the simulator runs, but all at once end.
An error occurs on this:
mWebView.LoadDataWithBaseURL("", str1, "text/html", "utf-8", null);
WebView mWebView = FindViewById<WebView>(Resource.Id.webView1);
String str1 =
"<html>" +
"<head>" +
"<style type='text/css'>" +
"#font-face {font-family:SFont; src:url('file:///android_asset/fonts/MyFont.TTF');}" +
"#font-face {font-family:TFont; src:url('file:///android_asset/fonts/times.ttf');}" +
"Ptext {" +
"font-family: SFont;" +
"font-size: 19px;" +
"text-align: justify;" +
"}" +
"Etext {" +
"font-family: TFont;" +
"font-size: 13px;" +
"text-align: justify;" +
"}" +
"body {" +
"text-align: justify;" +
"}" +
"</style>" +
"</head>" +
"<body dir = rtl>" +
"<font style='opacity:0.79'>" +
"<font color='white'>" +
"<Ptext>" + "Hello Hello" + " " + "</Ptext>" +
"<Etext>" + "Hello Hello" + "</Ptext>" +
"</font>" +
"</body>" +
"</html>";
mWebView.SetBackgroundColor(Color.ParseColor("#00000000"));
mWebView.LoadDataWithBaseURL("", str1, "text/html", "utf-8", null);
ERRORS:
[ERROR:gl_surface_egl.cc(327)] No suitab EGL configs found.
[ERROR:gl_surface_egl_android.cc(23)] GLSurfaceEGL::InitializeOneOff faild.
[Error:browser_main_lppo.cc(698)]GLSurdace::InitializeOneOff faild
[FATAL:gl_Surface_android.cc(58)] Check failed: kGLImplementationNone != GetGLImplementation()(0 vs. 0)
I tried to load a .heic image using WKWebView.loadFileURL on iOS 11.4 but got a blank page.
(I am sure the url is right as I can preview it in xcode)
Convert "heic" image to jpeg data and load with the help of html as:
if fileExtension == "heic" {
guard let fileData = fileData,
let image = UIImage(data: fileData),
let jpegData = image.jpegData(compressionQuality: 1.0)
else {
return
}
let base64JPG = jpegData.base64EncodedString(options: .lineLength64Characters)
let htmlImgTag = "<img src=\"data:image/jpeg;base64, " + base64JPG + "\" alt=\"" + fileUrl.lastPathComponent + "\" />"
let imageHTML = "<!DOCTYPE html>" +
"<html lang=\"ja\">" +
"<head>" +
"<meta charset=\"UTF-8\">" +
"<style type=\"text/css\">" +
"html{margin:0;padding:0;}" +
"body {" +
"margin: 0;" +
"padding: 0;" +
"color: #363636;" +
"font-size: 90%;" +
"line-height: 1.6;" +
"background: black;" +
"}" +
"img{" +
"position: absolute;" +
"top: 0;" +
"bottom: 0;" +
"left: 0;" +
"right: 0;" +
"margin: auto;" +
"max-width: 100%;" +
"max-height: 100%;" +
"}" +
"</style>" +
"</head>" +
"<body id=\"page\">" +
"\(htmlImgTag)" +
"</body></html>"
webView.loadHTMLString(imageHTML, baseURL: nil)
}
i am working on a youtube based api website and want to get the complete information of a video.
i am doing this as
<?php $JSON_Data = json_decode(file_get_contents("https://gdata.youtube.com/feeds/api/videos/9Xhat18gkLw?v=2&alt=json")); ?>
and getting data using this method
channel is:<?php echo $JSON_Data->entry->author[0]->name->{'$t'}."<br>"; ?>description is:<?php echo $JSON_Data->entry->{'media$description'}->$t."<br>"; ?>published time:<?php echo $JSON_Data->entry->published->{'$t'}."<br>"; ?>duration time:<?php echo $JSON_Data->{'yt$duration'}->seconds."<br>"; ?>image link:<?php echo $JSON_Data->{'media$thumbnail'}[2]->url."<br>"; ?>title is:<?php echo $JSON_Data->entry->title->{'$t'}."<br>"; ?>
but i am successful in getting a few information like title, channel name and published time
channel is:Naatsworld
description is:
published time:2011-08-27T01:32:36.000Z
duration time:
image link:
title is:Owais Raza Qadri - Main So Jaon Ya Mustafa Kehte Kehte (Full Video Naat Album)!!!
i also want to get video duration, description and image link
please help me how to do this
See if this helps you lot :
<script type="text/javascript">
function youtubeFeedCallback(data) {
document.writeln('<img src="' + data.entry["media$group"]["media$thumbnail"][0].url + '" width="' + data.entry["media$group"]["media$thumbnail"][0].width + '" height="' + data.entry["media$group"]["media$thumbnail"][0].height + '" alt="Default Thumbnail" align="right"/>');
document.writeln('<b>Title:</b> ' + data.entry["title"].$t + '<br/>');
document.writeln('<b>Author:</b> ' + data.entry["author"][0].name.$t + '<br/>');
document.writeln('<b>Published:</b> ' + new Date(data.entry["published"].$t.substr(0, 4), data.entry["published"].$t.substr(5, 2) - 1, data.entry["published"].$t.substr(8, 2)).toLocaleDateString() + '<br/>');
document.writeln('<b>Duration:</b> ' + Math.floor(data.entry["media$group"]["yt$duration"].seconds / 60) + ':' + (data.entry["media$group"]["yt$duration"].seconds % 60) + ' (' + data.entry["media$group"]["yt$duration"].seconds + ' seconds)<br/>');
document.writeln('<b>Rating:</b> ' + new Number(data.entry["gd$rating"].average).toFixed(1) + ' out of ' + data.entry["gd$rating"].max + '; ' + data.entry["gd$rating"].numRaters + ' rating(s)' + '<br/>');
document.writeln('<b>Statistics:</b> ' + data.entry["yt$statistics"].favoriteCount + ' favorite(s); ' + data.entry["yt$statistics"].viewCount + ' view(s)' + '<br/>');
document.writeln('<br/>' + data.entry["media$group"]["media$description"].$t.replace(/\n/g, '<br/>') + '<br/>');
document.writeln('<br/>Watch on YouTube');
}
</script>
View demo
I'm trying to get current localisation using phonegap javascript api. Here is a sample code taken from phonegap website:
<script type="text/javascript" charset="utf-8">
// Wait for PhoneGap to load
//
document.addEventListener("deviceready", onDeviceReady, false);
// PhoneGap is ready
//
function onDeviceReady() {
navigator.geolocation.getCurrentPosition(onSuccess, onError);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'Altitude: ' + position.coords.altitude + '<br />' +
'Accuracy: ' + position.coords.accuracy + '<br />' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy + '<br />' +
'Heading: ' + position.coords.heading + '<br />' +
'Speed: ' + position.coords.speed + '<br />' +
'Timestamp: ' + new Date(position.timestamp) + '<br />';
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
</script>
If I remove geolocalisation code, the application works well.
Any ideas ?
Thanks in advance,
If you are seeing the error in Android, you want to add the enableHighAccuracy flag:
navigator.geolocation.getCurrentPosition(onSuccess, onError, { enableHighAccuracy: true });
I have just tried it on PhoneGap 1.4.1, iOS Simulator 5.0 and it works fine.
What kind of error are you getting ?
if you are trying it on android device then altitudeAccuracy property is not support by Android devices, it will always return null.