Natural Text Generation based on key-value pairs - tensorflow

I have 40 entities forming a table. These entities consist of numerical or alphabetical key:value pairs in the context of real estate.
A table could look like this:
- Address 10066 Cielo Dr BEVERLY HILLS, CA 90210 UNITED STATES
- Price: $69,995,000
- Interior: 21,000 Sq Ft.
- Property Type: Single Family Home
- Year Home Built: 1996
Based on this table, which is generated synthetically, I would like to develop a grammatically correct natural text that considers the entire set of key:value pairs.
In our example, something like this:
"The property is located at 10066 Cielo Dr BEVERLY HILLS, CA 90210 UNITED STATES and costs
$69,995,000. The beautiful interior of the Single Family home sums up to 21,000 Sq Ft. The home was built in 1996."
I learned that GAN BERT might be the approach for this problem. Would it be possible to make that work or do you know a better approach?
Thanks for any sort of help, I really appreciate it!
NLPChoppa

Related

Is there an API to get a full citation (such as a BibTeX or JSON citation) from an arbitrary URL?

Say I have a URL like https://www.science.org/doi/10.1126/science.abb4363, how can I get the full citation as:
#article{
doi:10.1126/science.abb4363,
author = {Sergio Almécija and Ashley S. Hammond and Nathan E. Thompson and Kelsey D. Pugh and Salvador Moyà-Solà and David M. Alba },
title = {Fossil apes and human evolution},
journal = {Science},
volume = {372},
number = {6542},
pages = {eabb4363},
year = {2021},
doi = {10.1126/science.abb4363},
URL = {https://www.science.org/doi/abs/10.1126/science.abb4363},
eprint = {https://www.science.org/doi/pdf/10.1126/science.abb4363},
abstract = {There has been much focus on the evolution of primates and especially where and how humans diverged in this process. It has often been suggested that the last common ancestor between humans and other apes, especially our closest relative, the chimpanzee, was ape- or chimp-like. Almécija et al. review this area and conclude that the morphology of fossil apes was varied and that it is likely that the last shared ape ancestor had its own set of traits, different from those of modern humans and modern apes, both of which have been undergoing separate suites of selection pressures. Science, this issue p. eabb4363 A Review describes the unique and varied morphologies in fossil and modern apes, including humans. Humans diverged from apes (chimpanzees, specifically) toward the end of the Miocene ~9.3 million to 6.5 million years ago. Understanding the origins of the human lineage (hominins) requires reconstructing the morphology, behavior, and environment of the chimpanzee-human last common ancestor. Modern hominoids (that is, humans and apes) share multiple features (for example, an orthograde body plan facilitating upright positional behaviors). However, the fossil record indicates that living hominoids constitute narrow representatives of an ancient radiation of more widely distributed, diverse species, none of which exhibit the entire suite of locomotor adaptations present in the extant relatives. Hence, some modern ape similarities might have evolved in parallel in response to similar selection pressures. Current evidence suggests that hominins originated in Africa from Miocene ape ancestors unlike any living species.}}
I was able to download the citation by visiting the link manually, but are there any programmatic APIs to convert a URL (like even a Wikipedia URL) into a formal citation? If not, I am not sure what is the recommended approach to getting these efficiently.

Pyspark (from csv file) is loading dataframe in a different format

(I am new to pyspark)
I am trying to read a csv file into a pyspark dataframe as follows:
from pyspark import SparkConf, SparkContext
from pyspark.sql import SparkSession, SQLContext
spark = SparkSession.builder.master("local[1]").appName("SampleWork").getOrCreate()
df = spark.read.csv('train.csv',sep=",",header=True,inferSchema=True)
But I am not getting expected result dataframe here. How to read this file correctly.
I have added the first 3 rows of the sample csv file here.
csv file:
id,url_legal,license,excerpt,target,standard_error
c12129c31,,,"When the young people returned to the ballroom, it presented a decidedly changed appearance. Instead of an interior scene, it was a winter landscape.
The floor was covered with snow-white canvas, not laid on smoothly, but rumpled over bumps and hillocks, like a real snow field. The numerous palms and evergreens that had decorated the room, were powdered with flour and strewn with tufts of cotton, like snow. Also diamond dust had been lightly sprinkled on them, and glittering crystal icicles hung from the branches.
At each end of the room, on the wall, hung a beautiful bear-skin rug.
These rugs were for prizes, one for the girls and one for the boys. And this was the game.
The girls were gathered at one end of the room and the boys at the other, and one end was called the North Pole, and the other the South Pole. Each player was given a small flag which they were to plant on reaching the Pole.
This would have been an easy matter, but each traveller was obliged to wear snowshoes.",-0.340259125,0.464009046
85aa80a4c,,,"All through dinner time, Mrs. Fayre was somewhat silent, her eyes resting on Dolly with a wistful, uncertain expression. She wanted to give the child the pleasure she craved, but she had hard work to bring herself to the point of overcoming her own objections.
At last, however, when the meal was nearly over, she smiled at her little daughter, and said, ""All right, Dolly, you may go.""
""Oh, mother!"" Dolly cried, overwhelmed with sudden delight. ""Really?
Oh, I am so glad! Are you sure you're willing?""
""I've persuaded myself to be willing, against my will,"" returned Mrs. Fayre, whimsically. ""I confess I just hate to have you go, but I can't bear to deprive you of the pleasure trip. And, as you say, it would also keep Dotty at home, and so, altogether, I think I shall have to give in.""
""Oh, you angel mother! You blessed lady! How good you are!"" And Dolly flew around the table and gave her mother a hug that nearly suffocated her.",-0.315372342,0.480804970
b69ac6792,,,"As Roger had predicted, the snow departed as quickly as it came, and two days after their sleigh ride there was scarcely a vestige of white on the ground. Tennis was again possible and a great game was in progress on the court at Pine Laurel. Patty and Roger were playing against Elise and Sam Blaney, and the pairs were well matched.
But the long-contested victory finally went against Patty, and she laughingly accepted defeat.
""Only because Patty's not quite back on her game yet,"" Roger defended; ""this child has been on the sick list, you know, Sam, and she isn't up to her own mark.""
""Well, I like that!"" cried Patty; ""suppose you bear half the blame, Roger. You see, Mr. Blaney, he is so absorbed in his own Love Game, he can't play with his old-time skill.""
""All right, Patsy, let it go at that. And it's so, too. I suddenly remembered something Mona told me to tell you, and it affected my service.""",-0.580117966,0.476676226
You can use the custom escape character with the multiLine option.
df = spark.read.csv("test.csv", header=True, inferSchema=True, escape="\"", multiLine=True)
+---------+---------+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------------+
|id |url_legal|license|excerpt |target |standard_error|
+---------+---------+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------------+
|c12129c31|null |null |When the young people returned to the ballroom, it presented a decidedly changed appearance. Instead of an interior scene, it was a winter landscape.
The floor was covered with snow-white canvas, not laid on smoothly, but rumpled over bumps and hillocks, like a real snow field. The numerous palms and evergreens that had decorated the room, were powdered with flour and strewn with tufts of cotton, like snow. Also diamond dust had been lightly sprinkled on them, and glittering crystal icicles hung from the branches.
At each end of the room, on the wall, hung a beautiful bear-skin rug.
These rugs were for prizes, one for the girls and one for the boys. And this was the game.
The girls were gathered at one end of the room and the boys at the other, and one end was called the North Pole, and the other the South Pole. Each player was given a small flag which they were to plant on reaching the Pole.
This would have been an easy matter, but each traveller was obliged to wear snowshoes.|-0.340259125|0.464009046 |
|85aa80a4c|null |null |All through dinner time, Mrs. Fayre was somewhat silent, her eyes resting on Dolly with a wistful, uncertain expression. She wanted to give the child the pleasure she craved, but she had hard work to bring herself to the point of overcoming her own objections.
At last, however, when the meal was nearly over, she smiled at her little daughter, and said, "All right, Dolly, you may go."
"Oh, mother!" Dolly cried, overwhelmed with sudden delight. "Really?
Oh, I am so glad! Are you sure you're willing?"
"I've persuaded myself to be willing, against my will," returned Mrs. Fayre, whimsically. "I confess I just hate to have you go, but I can't bear to deprive you of the pleasure trip. And, as you say, it would also keep Dotty at home, and so, altogether, I think I shall have to give in."
"Oh, you angel mother! You blessed lady! How good you are!" And Dolly flew around the table and gave her mother a hug that nearly suffocated her. |-0.315372342|0.48080497 |
|b69ac6792|null |null |As Roger had predicted, the snow departed as quickly as it came, and two days after their sleigh ride there was scarcely a vestige of white on the ground. Tennis was again possible and a great game was in progress on the court at Pine Laurel. Patty and Roger were playing against Elise and Sam Blaney, and the pairs were well matched.
But the long-contested victory finally went against Patty, and she laughingly accepted defeat.
"Only because Patty's not quite back on her game yet," Roger defended; "this child has been on the sick list, you know, Sam, and she isn't up to her own mark."
"Well, I like that!" cried Patty; "suppose you bear half the blame, Roger. You see, Mr. Blaney, he is so absorbed in his own Love Game, he can't play with his old-time skill."
"All right, Patsy, let it go at that. And it's so, too. I suddenly remembered something Mona told me to tell you, and it affected my service." |-0.580117966|0.476676226 |
+---------+---------+-------+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+------------+--------------+

Google Reverse Geocoding - how to choose between a street_address or route?

I have been using Google's reverse geocoding APIs in a vehicle tracking application to convert lat/lon information into an "address" for at least 5 years. Recently, this conversion has started yielding some surprising results.
For example, the lat/lon pair, 36.7653111,-121.74852, when plugged into Google Maps, yields "CA-156, Castroville, CA 95012" as the address. This is the desirable answer.
The tracking application yields "11298 Haight St, Castroville, Monterey County, CA, 95012, US" The problem is that the JSON result contains two "street_address" and one "route" type. The dumb algorithm of choosing the first street_address or route occurring in the result no longer works. The question now is how to decide which of the possibilities is a better match to the given lan/lon? The lat/lon is clearly on route CA-156. Haight St. does not cross CA-156 at all.
What is special about this case is that the vehicle is not travelling on either of the streets in the two "street_address" types but is on the street in the route. In this case, the route should have been given priority over the two street_address types.
I have now examined the results of hundreds of reverse geocodings. There does not appear to be any simple algorithmic way of choosing the best result. For example, reverse geocoding 37.31674,-122.0472125 returns only two results:
Type: premise
Address: Child Development Center, Cupertino, Santa Clara County, CA 95014, US
location_type: ROOFTOP
37.316425,-122.0460558 Distance: 354.7286202778164 Feet
Type: route
Address: CA-85, Cupertino, Santa Clara County, CA 95014, US
location_type: GEOMETRIC_CENTER
37.3145586,-122.0461306 Distance: 855.4738140974437 Feet
The vehicle is travelling on CA-85. Choosing the first result (premise) or the result with least distance, does not yield the best result.
The fundamental problem here is the for "route" types, the distance to the GEOMETRIC_CENTER does not tell you if you are "on the route" (0 distance) or if you are "off the route", how far off.
I have filed a case with Google. If I get a useful response, I will post it here.
If you are reverse geocoding lat/lon information coming from in-vehicle devices here are two approached that significantly improve the results. The discussion assumes you have limited the results to types: "premise", "street_address" or "route", If you are interested in other types, you may have to experiment a bit.
First, if the in-vehicle device returns the speed along with lat/lon, then choose the "route" result, if one is present, when the speed is above a certain threshold. Otherwise, choose the "street_address" or "premise" with the least distance to the lat/lon. You may have to experiment a bit with the speed threshold to find a reasonable value. For me, 25 MPH seemed to do a decent job.
Second, if you don't have speed or another indication that the vehicle is stopped or moving, then try the following "hack".
Scan the results up to the first occurrence of a "route" and determine amongst "premise" or "street_address" types the one with the least distance to the lat/lon. Remember the "route", if one is found.
Then
1. If no "route" result exists, return the "premise" or "street_address" with the least distance to the lat/lon.
2. Else
a. If the "route" has a "route" name that matches the regex "[A-Z]+-[0-9]+", return the route as the best result.
b. Else if a least distance "premise" or "street_address" exists, return that as the best result.
c. Otherwise, return the "route" as a best result.
This is far from perfect, but seems to work well enough for the US which is all I care about right now. As route names differ significantly from country to country some enhancement will likely be necessary.

DL QUERY : Pizza Ontology : Is there a way to get the toppings ON the pizza? [duplicate]

I'm using Protege v4.3 for making ontologies.
I have a question about OWL ontology and DL query.
For instance, in the Pizza ontology,
http://owl.cs.manchester.ac.uk/co-ode-files/ontologies/pizza.owl
I can execute the DL query
hasTopping some CheeseTopping
The result is
American, AmericanHot, Cajun,.. etc. That's OK.
Now, i tried DL query
isToppingOf some American
But the result is nothing.
Because the property isToppingOf is inverse property of hasTopping,
I expected to get the result including FourCheesesTopping, CheeseyVegetableTopping, etc. from that query(by inference). Bud it didn't.
Is there any ways automatic reasoning like that?
The class expression
hasTopping some CheeseTopping
is the set of individuals each of which is related to some CheeseTopping by the hasTopping property. In the Pizza ontology, where there are no individuals, you can still get class subclass results for this query because the definition of certain types of Pizzas (e.g., American) are such that any Pizza that is an American must have such a topping.
Now, the similarly-structured query
isToppingOf some American
is the set of individuals each of which is related to some American pizza by the isToppingOf property. However, the Pizza ontology defines no particular individuals, so there aren't any individuals as candidates. But what about classes that might be subclasses of this expression? For instance, you mentioned the FourCheeseTopping. Now, some particular instance of FourCheeseTopping, e.g., fourCheeseTopping23 could be a topping of some American pizza, e.g.:
fourCheeseTopping23 isToppingOf americanPizza72
However, fourCheeseTopping might not have been placed on any particular pizza yet. When we choose an arbitrary individual of type FourCheeseTopping, we can't infer that it is a topping of some American pizza, so we cannot infer that the class FourCheeseTopping is a subclass of
isToppingOf some American
because it's not the case that every instance of FourCheeseTopping must be the topping of some American pizza. For a similar case that might make the logical structure a bit clearer, consider the classes Employer and Person, and the object property employs and its inverse employedBy. We might say that every Employer must have some Person as an Employee (since otherwise they wouldn't be an employer):
Employer ⊑ employs some Person
However, since a person can be unemployed, it is not true that
Person ⊑ employedBy some Employer
even though employs and employedBy are inverses.
What you can do, though, if you want to know whether toppings of a particular type could be placed an pizza of a particular type, is to ask whether
PizzaType ⊓ ∃hasTopping.ToppingType
is equivalent to, or a subclass of, owl:Nothing. For instance, since an American pizza has only toppings of type TomatoTopping, MozzarellaTopping, and PeperoniTopping [sic], the class
American ⊓ ∃hasTopping.MixedSeafoodTopping
is equivalent to owl:Nothing:
On the other hand, since an American pizza must have a MozzarellaTopping, the class
American ⊓ ∃hasTopping.MozzarellaTopping
is equivalent to American:
When you ask what are the subclasses of:
isToppingOf some American
you are asking what classes contain toppings that are necessarily used on top of American pizzas. But in the pizza ontology, no such class exists. Consider cheese toppings: Are all cheese toppings on top of some American pizzas? No, some cheese toppings are on top of Italian pizzas. The same holds for all topping classes.

Storage capacity for a magnetic swipe card

Any idea regarding the usual storage capacity of a magnetic swipe card ( like the ones that are used in ATM's ) ?
(PS : Tried googling but didn't get anything satisfactory and point on)
From http://en.wikipedia.org/wiki/Magnetic_stripe, it appears that the card is composed of three tracks (as previously mentioned by Pax), and Tracks 1 and 3 have a bit density of 210 bits/inch, while Track 2 has a bit density of 75 bits per inch.
If the strip is 3.25" long, then it can theoretically store 1607 bits, with 682 on each of Tracks 1 and 3, and 243 on Track 2.
ISO 7813 specifies the layouts for track 1 and 2. Track 3 is covered by ISO 4909.
Track 2 is the one commonly used for banking.
See ISO7813 and ISO4909 for details. Sorry, no wikipedia for 4909, you'll have to buy the docs from ISO or your country's standards body.