# Cryptocurrency

## Summary

A cryptocurrency is a digital currency that can be used to buy goods and services, but it has other purposes as well. Cryptocurrencies differ on the basis of their technology, purpose, privacy, and performance. Because they're transacted in cyberspace, they're also called **virtual or digital currencies**. By one estimate (Jan 2022), there are 16,300+ cryptocurrencies.

Cryptocurrencies are created using cryptographic techniques that make them secure. Many of them are based on blockchain technology but there are some that don't use blockchain. This blockchain is distributed across a network of computer systems. No single computer controls the blockchain.

Cryptocurrencies have their challenges. They've been used to conduct illegal activities in an untraceable manner. They can be stolen. Their valuations are volatile, leading to speculative trading. Regulations are not mature or simply non-existent in many countries.

## Discussion

### How are cryptocurrencies different from fiat currencies?

Fiat currencies (dollars, euros, etc.) are issued and backed by governments. Governments also control the supply and this scarcity gives them value. The financial system and transactions are governed by a central bank. Apart from cash transactions, online transactions and cheque payments require intermediaries such as banks. These intermediaries often charge a commission. Transactions can be reversed if necessary.

Cryptocurrencies are not backed by any government or central bank. Trust in these currencies comes from consensus among participants. Trust is placed in the underlying technology, which is decentralized. No single entity controls the technology. Cryptocurrencies themselves have mechanisms to limit supply. Transactions can happen directly without intermediaries or commissions. Transactions are permanently recorded: they can't be erased or reversed.

However, both fiat currencies and cryptocurrencies can be used to pay for goods and services, though cryptocurrencies are not widely used for this purpose at the moment. Both store value so long as there's continuing trust.

### Which are the main cryptocurrencies?

From the thousands of cryptocurrencies, Bitcoin is the most famous one, followed by Ethereum. Cryptocurrencies other than Bitcoin are generally called *altcoins*.

Cryptocurrencies can be categorized as follows:

    + **Payments**: Bitcoin was created as a currency for fast and cheap cross-border payments.
    + **Infrastructure**: Ether is the crypto asset of Ethereum. To use applications on Ethereum, ethers are bought and spent. Other cryptocurrencies can build on top of Ethereum. Augur is an example.
    + **Services**: Created to offer a service. Siacoin provides decentralized cloud storage. MANA can be used to buy virtual land on the Decentraland application. LUNA (from Terra), a DeFi coin, enables decentralized finance. Dentacoin serves the healthcare industry.
    + **Stablecoins**: Better stores of value since Bitcoin is highly volatile. Tether, USD Coin and Binance USD are examples. They're pegged against the U.S. Dollar.
    + **Privacy Coins**: Offer greater privacy for transacting parties. They've been popular among hackers distributing ransomware. Eg. Monero, Zcash and Dash.
    + **Meme Coins**: Created as a joke but have become successful. Eg. Dogecoin, Shiba Inu and Dogelon Mars.
    + **Interoperability Coins**: Used on platforms that enable different blockchains to interoperate. Examples of these cryptocurrencies (and their platforms) are Dot (Polkadot), Link (Chainlink) and Atom (Cosmos).

### Are crypto coins the same as crypto tokens?

There are two broad categories of cryptocurrencies: coins or tokens. Coins are used for payments but tokens have a variety of uses, often in application-specific ways. Coins can be viewed as digital money whereas tokens as programmable assets. Smart contracts rely on tokens. Such contracts give proof of ownership to real-world assets.

Tokens are issued through a process called Initial Coin Offering (ICO). Investors get tokens in return for their money. This money is used to develop a product or service to which investors get special access. Tokens themselves can be currency tokens, asset tokens, security tokens, reward tokens, utility tokens, or non-fungible tokens (NFTs).

Coins are native to their own blockchains but that's not the case with tokens. Bitcoin, Ethereum, Cardano and Polkadot run on their own blockchain platforms. USD Coin, Crypto.com Coin and Wrapped Coin are tokens that run on the Ethereum platform.

However, the distinction between coins and tokens is not always clear. CryptoSlate website shows coin and token rankings, and some cryptocurrencies appear in both lists.

### What are the main technical differences among various cryptocurrencies?

An important difference is how coins are produced and spent, their privacy and transaction speed. Some cryptocurrencies such as Bitcoin, Dash and Monero are created by a process called *mining*. Miners use powerful computers to solve complicated mathematical problems. Other currencies such as NEM (XEM) don't require mining. Ripple and IOTA are produced by organizations that create them.

In terms of privacy and performance, transactions in Dash or Monero are faster than those in Bitcoin. Litecoin validates a block in 2.5 minutes whereas Bitcoin requires 10 minutes. Litecoin uses *scrypt* algorithm for hashing instead of Bitcoin's SHA-256.

While many cryptocurrencies use blockchain as the underlying technology, IOTA is one that uses *tangle* instead. More technically, it's based on directed acyclic graphs. IOTA was created to secure data for the Internet of Things (IoT). Even when cryptocurrencies use blockchain there are differences. In a blockchain, participants agree on transactions by consensus. Bitcoin uses Proof of Work (PoW) as the consensus algorithm but Solana use a mix of Proof of Stake and Proof of History.

### How does a cryptocurrency work?

Most cryptocurrencies run on blockchain technology. A blockchain is a digital ledger (or database) of transactions. It's distributed across a network of computer systems but no single computer controls the network. Instead, this decentralized network of computers runs the blockchain and authenticates transactions.

Each computer is called a **node**. Each node performs a few main functions: relay transactions to other nodes, process transactions, and maintain the database of transactions. Many transactions are grouped into a **block**. Blocks are then connected in chronological order in a long, unbroken chain called **blockchain**.

**Mining** itself is the process of validating a transaction to prevent fraud. A node that validates transactions is also called a **miner**. Validation is simply a miner solving a complex mathematical problem. The cost of the hardware and energy required to solve this problem is very high. The miner that solves the problem first earns the right to post the transaction to the ledger and gets the cryptocurrency as the financial reward.

Every block is timestamped to indicate when it was validated. Timestamp used is the median of timestamps returned by all nodes of the network.

### How can cryptocurrencies be bought and sold?

Cryptocurrencies can be bought either via a cryptocurrency exchange or through brokers. Cryptocurrency exchange is a platform where people buy and sell cryptocurrencies. They have relatively lower fees than brokers. Cryptocurrency brokers are the intermediaries that execute transactions on your behalf and charge a fees for it. They also trade through exchanges.

To buy cryptocurrencies through an exchange, a user creates an account with the exchange. The user needs to verify the account to prevent fraud and meet federal regulatory requirements. The next step is to deposit real-world money into the chosen exchange. Now the user can buy any cryptocurrency out of hundreds of options.

A cryptocurrency can be exchanged for real-world money. Or it can be converted to any other cryptocurrency using exchange platforms such as Coinbase, Gemini and Trust Wallet.

### What options do I have to store cryptocurrencies?

Cryptocurrency exchanges are not backed by banks and they're loosely regulated. So they're at risk of theft or hacking. An investor can lose all his money if he forgets or loses the codes to access his account. Hence, it's very important to have a secure storage.

Some storage methods include:

    + **On the Exchange**: Cryptocurrencies are generally stored in a crypto wallet on the exchange. For higher safety, it's better to use a hot or cold wallet.
    + **Hot Wallets**: These are crypto wallets that are accessible online and run on internet-connected devices, such as tablets, computers or phones. Hot wallets are convenient, but there's still a risk of theft since they operate on the internet.
    + **Cold Wallets**: Cold crypto wallets aren't connected to the internet. They are stored in external devices, such as USBs or hard drives. Precaution is a must with cold wallets because if the keycode is lost or the device fails or breaks, the cryptocurrency may not be recovered ever.
    + **Physical Coins**: Bitcoin investors can purchase physical coins corresponding to the amount of bitcoins they purchased, with tamper-proof sticker covering a predetermined amount of Bitcoin.

### What are the technological limitations of cryptocurrencies?

The biggest technological limitation is the theft of currency. There have been many incidents when people or organizations have lost it all. In 2014, Fr33 Aid, an anarchist mutual aid organisation had it's Bitcoins stolen from it's online wallet located at Blockchain.info. Approximately 23 bitcoins were stolen, valued at more than 1 million dollars. Similar thefts have occurred at other exchange platforms including Coinbase and MtGox. MtGox went through a $500 million theft that ultimately brought down the exchange.

Cryptographic private keys can be lost from local storage due to malware, data loss or the destruction of the physical media. This results in the permanent loss of money. Perhaps another limitation is that transactions are irreversible.

Bitcoin, Ethereum and Dash are examples that require resource-intensive, high-energy-consuming mining. According to Bloomberg, 24 hours of crypto mining from around the world consumes around $150,000 in electricity.

### What are some criticisms of cryptocurrencies?

Cryptocurrencies are seen as threatening the establishment, which may result in outright bans or tight regulations. If so, they may not succeed as digital money. High transaction fees charged by exchanges may be an additional discouragement. Due to price volatility, they're not even good as stores of value. Transactions are also not really anonymous unless participants use one of the privacy coins. While built on decentralized technology, it's not really democratic since control is with miners, exchanges and platform owners.

### How are different countries adapting cryptocurrencies?

Government of different countries have different stands on the usage of cryptocurrencies. While some developed countries such as US, UK and Canada have allowed them for transactions, Zimbabwe, Kuwait and Bahrain have put an implicit ban on it. China, Bangladesh, Nepal, Qatar and Egypt have put an absolute ban on their use.

El Salvador is the first country to adopt cryptocurrencies as a legal tender. In Latin America, high inflation and volatility of fiat currencies have made cryptocurrencies a safer alternative. Cryptocurrencies are seen as better store of value. They're also used for sending money home.

Estonia has strict regulations. Licenses must be obtained, which includes paying a licensing fee, registering a headquarters physically located in Estonia and identifying customers. This resulted in withdrawal of 1,000 activity licenses of virtual currency companies in 2020.

### Which are the cryptocurrency exchanges out there and what cryptos do they support?

There are many cryptocurrency exchanges such as Coinbase, Gemini and Binance US. Different exchanges have different interfaces. Following are a few of the many exchanges:

    + **Coinbase**: According to Forbes, Coinbase is one of the best cryptocurrency exchanges. It offers services in many different cryptocurrencies such as Ethereum Classic, XRP, and Stellar Lumens; but it doesn't support Dogecoin.
    + **Crypto.com**: It supports access to 180 different cryptocurrencies. It doesn't charge any trading fee.
    + **Gemini**: It offers a trading platform that's easy to use for beginners, but the fee structure is higher than other exchanges.
    + **Etoro**: It supports 17 different cryptocurrencies. It offers service in 44 states in the US only.

## Milestones

1983

American cryptographer David Chaum develops **eCash**. The platform allows people to transfer money anonymously over the internet.

1995

DigiCash, an organization founded by David Chaum based on the eCash concept, gains popularity. It's an early form of cryptographic electronic payments that requires user software for withdrawing or sending payments.

1996

National Security Agency of United States publishes a paper entitled *How to Make a Mint: the Cryptography of Anonymous Electronic Cash*, describing a cryptocurrency system.

1998

The term **cryptocurrency** is officially established. DigiCash of David Chaum goes bankrupt. Wei Dai publishes B-money based on a decentralized crypto model.

2009

Pseudonymous developer Satoshi Nakamoto, creates the first decentralized cryptocurrency named **Bitcoin**.

2013

Billy Markus and Jackson Palmer release a new decentralized cryptocurrency named **Dogecoin**.

2014

UK commissions a study of cryptocurrencies and the role they could play in the UK economy.

2015

Vitalik Buterin, Gavin Wood, Charles Hoskinson, Anthony Di Iorio and Joseph Lubin release a new decentralized cryptocurrency named **Ethereum**.

2021

El Salvador becomes the first country to accept Bitcoin as legal tender. Government of China, the largest market of cryptocurrency, declares all cryptocurrency transactions illegal, completing a crackdown on cryptocurrency.

2022

Bitcoin becomes the largest cryptocurrency with a market capitalization of $882 billion, followed by Ethereum at $447 billion. Binance Coin, Tether and Solana follow at $86 billion, $78 billion and $52 billion respectively.

Cryptocurrency


# IoT Analytics

## Summary

IoT analytics involves analyzing data coming from the Internet of Things (IoT) and deriving useful insights from this data.

IoT analytics is usually discussed within Industrial IoT (IIoT). Data is collected from manufacturing infrastructure, meteorological stations, smart meters, delivery vans, and various sensors on all types of machines. IoT analytics can also be applied to retail and healthcare sectors. Data can be in different formats such as video feeds, geolocation data, social media data, or log files. Given the different types of information sources, data integration can be very difficult. This is exactly where IoT analytics makes a difference.

## Discussion

### Could you showcase IoT analytics with some examples?

By adopting IoT for monitoring, control and automation, Deep Sky Vineyard improved efficiency. By optimizing farming schedules, labour efficiency increased by 30%. Crop efficiency increased by 50% by reducing loss due to rotting, etc. Water flow and soil moisture are monitored to achieve consistent yields and quality.

Siemens Healthineers applied IoT to detect anomalies in x-ray tube production using multivariate time series. Specifically, they determine the quality of liquid metal bearings. They're also able to identify how much each variable contributes to the anomaly.

Audi's Neckarsulm factory does 5 million welds per day. Manual inspection of weld quality is expensive. Voltage and current data from welding gun controllers are collected. These are combined with data on weld configuration, metal types, and electrode health. Audi does analytics at the edge on Intel hardware to warn of possible faulty welds.

British oil and gas company BP fitted many of its wells with 20-30 GE sensors. Temperature, pressure and other parameters are measured. Each well sends 2 million data points per minute to GE's Predix cloud platform. This data helps BP predict well flows and useful life of a well, and see fleetwide performance.

### How does IoT analytics differ from traditional analytics?

Traditional analytics is done on structured data. IoT devices generate **unstructured data**. Data have different formats and are not standardized. Because sensors are affected by physical process and randomness, data may contain missing points, corrupted messages, and incorrect readings. This is unlike data entered by humans or scanned from forms.

Traditional data systems don't change that often. For example, when filling a form many fields have a predefined range. IoT systems are more **dynamic**. Device IP addresses may change. Devices may be upgraded. New devices may be installed with better capability. Environmental conditions may affect sensor accuracy or precision.

IoT data often comes in **real-time**. Many applications also require real-time analysis and insights. In fact, it's been said that much of IoT data becomes stale and useless if not analyzed immediately. Deciding whether to give someone a loan based on analysis of past behaviour is non-real-time traditional analysis. But to know available parking spaces requires IoT analytics in real-time.

### What does it mean to state that IoT data needs context?

Raw data collected by sensors is called **content**. It's value can be enhanced by bringing in **context**, which is about associating a data stream with other data streams and business goals.

Analysis on any device's data stream can be enhanced by combining it with other related data streams. Relationships across data sources can be modelled digitally. These relationships become useful when we run analytics queries. In the figure, a household's power consumption from the grid is enhanced by including all other households on that street or all households fed by the same power station. These multiple streams are used to more accurately interpolate missing data points or detect anomalies.

Data collected by sensors on a machine on the factory floor can be enhanced with peak hours of machine use, yields, rejects, operator effectiveness, bottlenecks, material use estimates, and more. Another example is leak detection in oil pipelines. Context comes from integrating different types of data: pipeline inspection data, weather, dig reports, waterways, rain/flood zones, seismic activity, etc.

### What's a typical process flow in IoT analytics?

IoT analytics commonly adopts the following steps:

    + **Data Collection**: This step primarily comprises of data collected from various IoT sources including audio, image and light sensors. This heterogeneous nature of data raises the significance of IoT analytics technology.
    + **Data Pre-processing**: This step handles missing data, imports required libraries, encodes categorical data and does feature scaling.
    + **Analysis of Data**: This is mostly about exploratory data analysis that brings out summary statistics. It may suggest possible hypotheses and modelling approaches.
    + **Train and Test of data**: Data scientists build machine learning and deep learning models to suit business requirements. Models are trained from available data. With cross validation and online testing, the efficiency of the model is evaluated.
    + **Deployment and Improvement**: The tested model is deployed to deal with various real-world business problems.

### What are the various types of analytics in IoT?

**Descriptive analytics** is the most basic form that allows users to describe and aggregate incoming IoT data. Descriptive analysis is as simple as calculating mean and standard deviation. It can be used to quickly understand the data being collected.

**Diagnostic analytics** builds on the initial understanding provided by descriptive analytics. It seeks to explain why something happened in the past. It's really root cause analysis but based on data and powered by algorithms. Data discovery, data mining, data drill down and drill through are some useful processes.

**Predictive analytics** looks at historical data to predict future events or behaviour. If a sensor starts showing data out of its usual range, this might indicate some fault. Predictive maintenance can be scheduled before things become worse. In an another example, a supplier can proactively analyse client inventory and do early or just-in-time delivery.

**Prescriptive analytics** is used to optimize decisions for the future to achieve a certain goal. For example, it might suggest best operating conditions to maximize efficiency or uptime.

### How is edge computing influencing IoT analytics?

With edge computing some of the work is done at the edge of the network. This is where IoT connects the physical world to the cloud. Edge computing is more than just computation and data processing on IoT devices. An integral part of this is the powerful and seamless integration between the IoT and the cloud, between the physical world and the computational world. Edge computing applications use the computing power of IoT devices to filter, pre-process, aggregate, or evaluate IoT data.

Some of the motivating factors for edge analytics are data privacy, latency and robustness. Some applications might permit processing of sensitive information only on devices. Applications that use image recognition may need low latency. Connectivity issues should not render applications unusable. All these are examples where cloud analytics may not be suitable.

Healthcare has many examples of edge analytics. Portable MRI machines and image processing software enable real-time analysis at bedside. Insulin pumps obtain current sugar levels from sensors, use algorithms to predict future sugar levels and then deliver correct amounts of insulin.

### What are some algorithms or techniques used in IoT analytics?

IoT uses many ML/AI algorithms, selected to match the needs of each application. Classification, clustering, estimation, denoising, and feature selection are some of these. Time-series analysis is an important technique. This can be time-series statistical analysis, data mining or search. One technique breaks data into chunks and uses incremental algorithms. This mitigates high memory requirements.

Edge computing mitigates large capacity requirements by distributing the processing and storage. Only some data that needs complex analytics or long-term storage go to the cloud. In some applications, only aggregates (sum, mean, min, max) are stored.

When it comes to real-time insights, data is analyzed as it flows into the analytics platform. This is called streaming analytics. Raw data may be stored in a data lake. Processed data is usually stored in databases or data warehouses.

Time-series data has its own customized databases: InfluxDB, Timescale, Prometheus, Redis, Kdb+, RRDtool, Amazon Timestream, and more. Moreover, IoT leverages many big data technologies including Apache Hadoop, Apache Spark, Apache Storm, SAP HANA, Apache Drill, and more.

### What are the major industries influenced by IoT analytics?

IoT analytics is playing an important role in manufacturing, retail, oil & gas and healthcare:

    + **Manufacturing**: This sector is defining the Industrial IoT (IIoT), Industry 4.0 and smart energy management. Machine learning, neural networks, and predictive methodologies are playing major roles. With these technologies, hidden trends, insights and correlations are established that help in strengthening the business structure.
    + **Retail**: IoT analytics in retail assist companies in providing a personalized experience to customers that turn them into repeat buyers. Data provides a contextual view about consumer preference.
    + **Oil & Gas**: Operational efficiency is improved and downtimes are reduced by fixing faults quickly or predicting impending failures. Analytics is also presenting new opportunities such as better pump designs, higher production, reservoir mapping, and more.
    + **Healthcare**: IoT analytics is unlocking valuable insights by analyzing data from various mobile devices and smart technologies such as sensors, heart rate monitors, thermometers and IVs. They help to gain a remote view of patients.

### What are the major barriers to adopting IoT analytics?

**Data privacy** is a concern for end users. Data from their devices may reveal personal information directly or via analytics. Those who collect the data don't always clarify how it will be stored, secured, shared or used.

Since IoT deals with physical systems (building automation, self-driving cars), **safety** is a major concern. Buggy apps, malware or communication failures can causes systems to fail and put lives in danger.

**Real-time analytics** itself is a challenge due to large volumes of data that demand fast processing and high amounts of storage.

IoT as a whole is **diverse and complex**. The architecture spans low-end sensors to high-end servers, edge analytics to cloud storage. Many types of data come in. Various technologies and workflows are used. Interoperability is an issue. Integrating many parts into one effective solution is a challenge. People need to be trained and ecosystems have to mature.

**Regulations** about data use are not transparent. The legal framework to handle data theft or misuse is also not mature.

## Milestones

1968

At General Motors, Dick Morley introduces Programmable Logic Controller (PLC) in the automatic transmission manufacturing division.

1975

Honeywell and Yokogawa introduce the technology of Distributed Computing System (DCS). Control is distributed across the system. Backup redundancies are available. The system eliminates a singular point of failure in a central control room.

1999

RFID as a technology starts gaining wider adoption. In subsequent years, devices equipped with Near-Field Communication (NFC), barcodes, QR codes and digital watermarking start gaining adoption within the IoT technology.

2002

With the growing popularity of cloud technology, its integration with IoT technology starts experiencing a linear growth rate. Further, this synergy allows the storage of IoT-based data in the cloud. Analysis of the historical data unlocks hidden patterns, thereby leading to the development of OPC Unified Architecture protocol in 2006.

IoT Analytics


# Text Summarization

## Summary

On the web, everyone can be a publisher. We're already seeing vast amounts of information being published daily in the form of restaurant/movie/book reviews, blogs, status updates, and more. In addition, traditional print publications (newspapers, magazines, technical journals, whitepapers) are also available online. It's impossible for anyone to keep track of recent publications even if limited to one domain. This is where text summarization can help.

A summary, created automatically by algorithms, typically contains the most important information. The summary should be mindful of the reader and the communication goals. It may also help the reader decide if the original text is worth reading in full. The summary can also help improve document indexing for information retrieval. An automated summary is often less biased than a human-written summary.

## Discussion

### What are some real-world applications of text summarization?

Here are some everyday examples of text summarization: news headlines, outlines for students, movie previews, meeting minutes, biographies for resumes or obituaries, abridged versions of books, newsletter production, financial research, patent research, legal contract analysis, tweeting about new content, chatbots that answer questions, email summaries, and more.

When Google Search presents search results, some entries are accompanied by auto-generated summaries. Google may be leveraging a knowledge graph for this purpose. Google's approach to summarization is mainly entity centric. Summarization extends to timelines and events about entities.

Doctors write long medical notes containing nutritional information for pregnant mothers. When these were reduced to short crisp summaries, pregnant mothers found them a lot easier to understand.

### Which are the main approaches to text summarization?

With **extractive summarization**, summary contains sentences picked and reproduced verbatim from the original text. With **abstractive summarization**, the algorithm interprets the text and generates a summary, possibly using new phrases and sentences.

Extractive summarization is data-driven, easier and often gives better results. Abstractive summarization is how humans tend to summarize text but it's hard for algorithms since it involves semantic representation, inference and natural language generation. Often abstractive summarization relies on text extracts.

For extraction, sentences are scored and those with highest scores are selected. Scoring criteria may include word frequencies, location heuristics, sentence similarity, rhetorical relations, and semantic roles.

Typically an intermediate representation is used to select relevant summary content. With **topic representation**, the intent is to identify the main topics in the text. Topic words, word frequencies (including TF-IDF), clustering, LSA and LDA have been applied to summarization. With **indicator representation**, a feature set is used to rank and select sentences. Examples of this approach are graph-based methods and machine learning.

### What are the challenges and requirements of multi-document summarization?

The pipeline for multi-document summarization (MDS) has the same basic steps as for single-document summarization (SDS): content selection, information ordering, and sentence realization. However, MDS has some unique challenges:

    + **Redundancy**: A single document has far less redundancy than a topically-related group of documents. Summary shouldn't repeat similar sentences. *Maximal Marginal Relevance (MMR)* is a scoring system to penalize similar sentences.
    + **Temporal Ordering**: A stream of news articles might be reporting the unfolding of an event. Summary should order them correctly and be sensitive to later developments overriding earlier ones.
    + **Cohesion and Coreference**: Both are important for information ordering. Sometimes cohesion might demand a certain ordering but cause coreference problems, such as a person's shortened name appearing before the full name.
    + **Compression Ratio**: Summarization becomes more difficult when more compression is demanded.MDS may cluster similar documents and passages. Summary should include sufficient context and right level of detail. Factual inconsistencies across documents can be reported. Finally, users must be allowed to filter out irrelevant content, dig deeper into the the sources via attribution, or compare related passages across documents.

### How does text summarization vary across domains or contexts?

Summarization must tune its output to each domain or context. For example, summarization of a news article would involve different considerations from that of a corporate sales report.

General text summarization techniques might not do well for specific domains. Summarizers therefore might wish to use domain-specific knowledge. For legal document summarization, *CaseSummarizer* is a tool. In biomedical domain, summaries are created of literature, treatments, drug information, clinical notes, health records, and more.

Summarizing scientific literature is a challenge due to length, complexity, and structure (tables and figures). *IBM Science Summarizer* is a tool that IBM created to summarize computer science publications. It extracts domain-specific entities of types task, dataset and metric.

Often there are extra clues about what might be important in a document. Summarization can use these for content selection. For example, comments and discussions on a blog post point to interesting content segments. Likewise, citations in scientific papers are useful pointers. For web summarization, it's possible to look at other pages linking to a particular page and determine the most suitable sentences.

### How has machine learning been applied to text summarization?

The common ML approach is to view text summarization as a classification problem. Algorithm is trained in a supervised manner on original text, an extractive summary and a set of features. Algorithm learns to classify sentences as either summary sentences or non-summary sentences.

Classifiers could be based on naive-Bayes, decision trees, SVM, HMM, and CRF. Often each sentence is classified independently of others. However, since HMM and CRF capture dependencies, they outperform other techniques.

The problem with supervised algorithms is in creating labelled data for training. This problem is worse for MDS. In a semi-supervised approach, a small amount of labelled data is used along with much larger amount of unlabelled data. The algorithm learns iteratively by classifying some unlabelled data in each iteration.

### Could you describe neural network architectures for text summarization?

The typical approach is to do **sequence-to-sequence modelling** since input is a sequence of words and the summary is also a sequence of words. In an encoder-decoder architecture, the encoder uses LSTM to give an input representation. The decoder is also an LSTM that generates the output sequence. An attention layer between the encoder and the decoder helps in determining the most relevant words for the summary.

Seq2seq models, LSTMs and attention layers have made abstractive summarization possible, even if they're not yet state-of-the-art compared to extractive summarization methods. These models are trained **end-to-end** without bothering to model each step of a traditional summarization pipeline. They also don't need access to specialized vocabulary or do pre-processing. This end-to-end approach has been applied successfully to short output sequences, such as news headlines or short email responses.

In a **pointer-generator** network, a generator provides new words whereas a pointer copies words from source text. Seq2seq models often produce repetitive sentences. A **coverage model** avoids repetitions.

Fernandes et al. showed that sequence encoders with a graph component does better at capturing long-distance relationships.

### How do I evaluate text summarization algorithms?

Human evaluation is the simplest. In 2004, **Recall-Oriented Understudy for Gisting Evaluation (ROUGE)** was created to automate evaluation by comparing against hand-crafted summaries. ROUGE-N, ROUGE-L, ROUGE-W, ROUGE-S, and ROUGE-SU are some metrics in this family.

Different people produce different summaries of the same text. Meaning shared across different human summaries is called Summary Content Unit (SCU). With a focus on meaning, **Pyramid Method** evaluates a summary using SCUs.

While there's no universal system of metrics, text summarizers are typically evaluated based on TREC, DUC and MUC systems. DUC (2001-2007) became a summarization track in TAC (2008-).

Datasets for supervised training of MDS algorithms are not common. For summarizing a single or a few documents, commonly used datasets are Gigaword, CNN/DailyMail, TAC (2008-2011) and DUC (2003-2004). ELI5 and WikiSum can be used for longform question answering and MDS respectively. Opinosis is a dataset of 51 article-summary pairs.

Released in 2018, Cornell Newsroom is the largest dataset for training and evaluating summarization systems. Spanning 1998-2017 and containing 1.3 million articles, it's been collected from newsrooms of 38 major publications. Summaries are obtained from search and social metadata.

### What are some useful resources for text summarization?

Pengfei Liu has curated a useful list of datasets, research papers, and groups researching on text summarization.

In Python, Gensim has a module for text summarization, which implements *TextRank* algorithm. An original implementation of the same algorithm is available as PyTextRank package. PyTeaser is a Python implementation of Scala's TextTeaser.

Back in 2016, Google released a baseline TensorFlow implementation for summarization.

## Milestones

Apr
1958

Luhn makes use of **word frequencies** to determine sentences most significant for summarization. Frequently occurring words close to one another suggest significant sentences. Thresholds are set to ignore most frequent and least frequent words. For example, in biology, the word 'cell' is too common and can be ignored. Luhn's algorithm, extractive in nature, is simple in that it doesn't merge word variations (differ, different, differently).

Apr
1969

In addition to word frequencies, Edmundson makes use of pragmatic or cue words, title and heading words, and structural indicators such as sentence location. He notes that these improve text extraction. Example cue words are 'significant', 'impossible' and 'hardly'. They're classified are positively relevant, negatively relevant and irrelevant. He hypothesizes that significant sentences or paragraphs occur very early and very late in the section or document. He also observes that future algorithms must consider language syntax and semantics. Statistical evidence alone is inadequate.

1995

Kupiec et al. implements a **supervised machine learning** algorithm based on the **naive-Bayes classifier**. Algorithm is trained on hand-selected extracts. The features considered include sentence length cut-off, fixed-phrase, paragraph, thematic word, and uppercase word. For example, the model ignores short sentences. It picks out thematic words, proper names and acronyms. Words such as 'conclusions', 'summary' or 'discussion' are more likely to be in the summary.

Dec
1997

For his PhD thesis on text summarization, Marcu takes inspiration from Rhetorical Structure Theory (RST). He looks at the **rhetorical relation** between two non-overlapping text spans called nucleus and satellite. Examples of such relations are justification, evidence, restatement, and concession. Text is decomposed into smaller units connected by rhetorical relations. In the example, *Justification* is the relation between Mars weather and its distant orbit.

Apr
2000

Radev et al. propose **centroid-based summarization** for multi-document summarization. Similar documents and sentences are grouped into clusters. Each cluster may represent a different sub-topic. Cluster centroid is a pseudo document representative of the cluster. Summary would include sentences similar to the centroids.

Oct
2000

Since RST is limited to single documents, Radev introduces **Cross-document Structure Theory (CST)** for multi-document summarization. He proposes multi-document graphs as a useful abstraction to represent relations at word, phrase, paragraph and document levels. He identifies 24 cross-document relations, such as Identity (same text), Subsumption (one sentence is contained in another), and Follow-up (additional information reflecting new developments). Summarization is done in four steps: clustering, document structure analysis, link analysis, and personalized graph-based summarization.

May
2004

Barzilay and Lee propose a domain-sensitive **content model**. They use **Hidden Markov Model (HMM)** in which domain topics are the states and generates sentences relevant to that topic. State transitions model topic change. An n-gram model is used to generate sentences. This model jointly learns both content selection and information ordering.

Jul
2004

Inspired by Google's PageRank algorithm, Mihalcea proposes *TextRank*, a **graph-based algorithm**. Each sentence is a node in the graph. Edges correspond to sentence similarities using a metric such as cosine similarity. A weighted graph is constructed from the text. A ranking algorithm (such as HITS, POS or PageRank) is run on the graph. Graph nodes with the best scores are selected for the summary.

2006

Wu proposes **event-based summarization**. Event terms could be verbs (incorporate) or action nouns (incorporation). Event elements are typically named entities (Person, Organisation, Location, Time). Document is represented as an event map on which PageRank algorithm is employed. The work of Li et al. is also event-based and it looks at intra-event and inter-event relevance.

Sep
2015

Rush et al. apply **neural networks for abstractive summarization**. Previous work on abstractive summarization relied on linguistic constraints or syntactic transformations. The proposed approach applies a neural language model along with an attention-based input encoder. They experiment with three different encoders: bag-of-words, convolutional (TDNN) and attention-based. The model using attention-based encoder performs best. Experiments are limited to headline generation based on only the first sentence. The model is trained on English Gigaword corpus. This work is improved by many others in 2016.

Aug
2016

Nallapati et al. use an **attentional encoder-decoder RNN** for abstractive summarization. Input embedding is feature-rich with word, POS, NER, TF, and IDF. A pointer-generator model handles rare or OOV words. The attention mechanism is hierarchical at word and sentence levels. Since existing datasets are limited to single sentence summaries, they present a new dataset from CNN/DailyMail news stories with an average of 53 words and 3.72 sentences in the summaries. This work establishes a baseline for abstractive summarization of long texts.

Jan
2018

As an exercise in multi-document summarization, Liu et al. attempt to **generate Wikipedia articles**. In the extractive stage, they select the most important content tokens. For the abstractive stage, they use a scalable decoder-only transformer architecture in which input and output sequences are combined into a single sequence. To make it scale for longer sequences, they introduce memory-compressed attention and local attention. The final model has five layers alternating between memory-compressed and local attention.

Oct
2019

Fan et al. show that using **knowledge graph representations** of the text as input to a seq2seq model gives better performance. The graph is linearized before it's given to a transformer encoder. Graph construction involves merging nodes and resolving coreferences.

Sep
2019

Liu proposes *BERTSUM*, a modification of BERT for summarization. The model encodes multiple sentences as a single input sequence. Interval segment embeddings are use to distinguish the sentences. For fine-tuning and capturing document-level features, he tries different summarization layers: simple classifier, RNN, inter-sentence transformer. He finds that two-layer inter-sentence transformer performs best.

Text Summarization


# Material Design

## Summary

Material Design is a design system or visual language that enables designers and developers achieve a unified UI/UX across devices and products. It's perhaps Google's first serious focus on design, rather than technology alone. By giving app creators design guidelines and tools, Google hopes to bring a consistent experience to users of its products and platforms, especially with Android.

Why "material"? Users feel and understand materials. By making design obey real-world effects at a level of abstraction, the interface will be more natural and intuitive to users. However, realism is not taken to the extreme like skeuomorphism. Material Design improves upon flat design by adding real-world effects. Materials have thickness. They cast shadows. They are solid and cannot pass through other materials. They obey laws of physics. These have been used in the creation of Material Design.

## Discussion

### What's the backstory for Material Design?

Early human-to-computer interfaces were command line interfaces. When graphical interfaces were invented in the 1980s, designers attempted to represent real-world objects digitally so that users could relate to icons and buttons due to their familiarity. Design elements had a sense of realism. We called this design philosophy *skeuomorphism*.

As users became tech savvy, such realism was no longer necessary. Meanwhile, better device displays allowed designers to add more details. In fact, too much detail can distract users from content and functionality. UI designs therefore moved towards minimalism that had solid colours, clear typography, no shadows and functional focus. This is what we called *flat design*. Its roots can be traced to the 1920s and later popularized by the Swiss Bauhaus School. Flat design was adopted by Microsoft Windows 8 (2012) and Apple's iOS7 (2013). With the rising popularity of mobile devices, flat design was easier for designers and users across device screen sizes.

Flat design had its critics for causing usability issues and limiting variety. What if we could combine elements skeuomorphism and flat design? Material Design does this by using material as the metaphor.

### What are the key principles of Material Design?

We can identify three key principles:

    + **Material is the metaphor**: By using shadows and animation, we create surfaces, edges, their relationships and their interactions. Inspired by materials and objects in the real world, Material Design aims to obey the laws of physics but also go beyond.
    + **Bold, graphic, intentional**: The idea is to create immersive user experience while giving emphasis to user actions and core functionality. Typography, edge-to-edge imagery (without margins), ample whitespaces and bold colours are just some techniques to achieve this.
    + **Motion provides meaning**: Motion must maintain focus and continuity of user experience even as objects transform and reorganize. It also provides useful feedback to user actions. User actions are seen as users giving energy to the UI.Nick Summers has shared more details of the above principles.

### What aspects of the interface does Material Design cover?

Material Design guidelines cover the following (and more):

    + **Motion**: Duration, guided focus, path of movement, fading, etc.
    + **Style**: Colour, icons, imagery, typography, etc.
    + **Layout**: Units and measurements, floating action buttons, grids, spacing, layout structure, responsive layout, etc.
    + **Components**: Buttons, cards, menus, lists, dividers, tabs, widgets, sliders, etc.
    + **Patterns**: Launch screens, navigation, notifications, search, settings, scrolling, etc.
    + **Growth & communications**: onboarding, feature discovery, gesture education, etc.

### Why does pressing a button make it rise up from the surface?

We normally think of a button as being raised from a surface in default mode. When pressed, it goes down towards the surface. In Material Design, buttons behave in the exact opposite manner. The z-axis property gives a component its elevation with respect to the surface. The surface is the digital device's display and components can only rise up (positive z values). Thus, button press should be seen as user interacting with the button and making it come towards the finger.

### How is motion conveyed?

Material documentation states,

> Motion in the world of Material Design is used to describe spatial relationships, functionality, and intention with beauty and fluidity.

Motion is inspired by physics with attention to gravity and friction. A ripple effect from the point of touch conveys user input. New surfaces emanate from components that create them. Transitions happen in arcs. Surfaces can be push, divide or join with each other. They can create hierarchy by interacting and stacking on top of each other with attention to surface thickness. Materials that grow, shrink or fade do so by decelerating or accelerating in time. Upward movement starts slow since we have to work against gravity and vice versa for downward movement. Transformations can originate from object's current location or from the center of final surface. Materials can move along any axes but z-movement is meant for user interaction.

### What tools has Google released to help designers working on Material Design?

Apart from design guidelines, Google supports designers with many tools and resources:

    + **Gallery**: A tool to manage design iterations and get feedback.
    + **Remixer**: Collaborate in real-time by adjusting colours, animations and more on the fly.
    + **Resizer**: An interactive viewer that helps designers test material design breakpoints across desktop, mobile, and tablet.
    + **Color Tool**: Create colour palettes, test accessibility, preview and share.
    + **Device Metrics**: A handy reference for sizing your UI across multiple devices.
    + **Stage**: Allows for dynamic interfaces with interactive motion.
    + **Icons**: A library of hundreds of material icons.
    + **Material Components**: Provides modular and customizable Material Design UI components. It comes in variants of Android, iOS and Web.

### Can you give some pointers for using Material Design in Android apps?

Android documentation talks about three goals:

    + Enchant the user. Combine beauty and simplicity. Be crisp and meaningful with typography.
    + Make life easier. Make the interface intuitive. Don't overwhelm.
    + Amaze the user. Empower them to try new things and be inventive. Allow for new workflows.Muneer gives more descriptions of the above.

Android comes with Material themes, lists, cards, and more. Shadows and layering can be created by using the Z property (surface elevation). A variety of Material animations can be used out of the box but developers can also create custom animations. In addition, a comprehensive Material Design training is available online.

### What frameworks out there support Material Design?

Among the free Material Design CSS frameworks are Materialize, MUI, Surface and Material-UI. Material Design Lite and Material Components for the Web are frameworks from Google folks. Google's Polymer has a category named Paper that includes Material Design components.

Many frameworks add Material Design support for existing front-end frameworks: Viu for Meteor, Vuetify.js for Vue.js, ember-cli-materialize for Ember.js, Ionic Material for Ionic, Material-UI for React, Angular Material and LumX for Angular.js, Material Design for Bootstrap and Phonon Framework for Cordova.

Beyond frameworks, there's a curated list of 300+ Material Design resources that developers will find useful. This includes colour palettes, icon sets, fonts, layout templates, UI kits, widgets, backgrounds, wallpapers, articles, design inspirations and more. Since animation is important in Material Design, Paul Andrew provides a list of animated Material Design examples for inspiration.

### Are there any criticisms of Material Design?

Developers used to flat design, may take more time to implement Material Design. They also have to learn and code for motion, which is an important design aspect. The design language is itself controlled by Google and not open sourced.

Nate Swanner has said that, "Material Design wants to make you feel as though you're touching something tangible, but you're not. You. Are. Tapping. A. Screen." He goes on say that he doesn't care for the 'clever' animations. Android apps running on iOS tend to use Material Design. This violates iOS platform conventions and angers iOS users. Also, a taste of Material Design within iOS is unlikely to influence users to switch to Android.

Rune Madsen gives specific examples of Material Design where Google's rules of design either constrain designers or simply ignore how designers actually work. For example, designers should be allowed to use bright colours for body text if they want to. The design guidelines also tend to enforce a certain style that's hard to break away from. Designers will be stuck with Google's branding. For that matter, Google itself is not adhering to the Material Design guidelines.

### Are there any criticisms of design systems in general?

A criticism of design systems is that they create a design monoculture. They also tend to benefit the designer more than the user. Users will obey a horrible system rather than complain. In fact, one Google designer stated that, "Material Design is a way for designers to get what they want."

In 2018, Google addressed some of this criticism by allowing users to customize the styling while retaining the consistency, usability and discoverability of Material Design. So it's not just about design guidelines but also about tools to adapt to specific design needs and branding.

In contrast, Amazon did not have a well-documented design system. Rather, it evolved an effective UI based on user feedback and continuous improvement.

### Could you compare Material Design with its alternatives?

Historically, we've had skeuomorphism and flat design for digital user interfaces. Flat design is more performant than skeuomorphism and distraction-free. But it may look boring and have usability issues. Skeuomorphism may look too real, distract users from content and render slower. Material Design combines the best of both. It has good documentation but developers may feel constrained by what Google considers as right.

It's been said that between flat design and Material Design, the differences are subtle, yet critical. While Material Design is still flat, it considers the third dimension along the z-axis. Material Design attempts to bring the real and the digital worlds closer. It's richer in interaction and user experience.

IBM Design Language is an alternative that's been commented as a copy of Material Design. In 2010, Microsoft introduced Metro design language that uses flat design and typography. An evolution of Metro is Microsoft's Fluent Design, which was applied to Windows 10 in October 2017.

## Milestones

2007

Some Google designers attempt to create a unified design across the company's products and platforms. It is named Kanna. The project doesn't take off due to lack of management support.

2011

The growth of compute power and broadband access gives UI/UX increasing importance. Mobile forces design to be taken seriously. Project Strawman aims to "redesign Google". Gmail is redesigned with flatter buttons, and more whitespace and margin. A year later, Google Now uses cards and well-designed typography. These changes are elements of what later becomes Material Design.

Jun
2014

Originally codenamed Quantum Paper, Google announces Material Design at its annual developer conference, Google I/O, in San Francisco. In November 2014, Android Lollipop becomes the first Android release to use Material Design.

Apr
2016

Faiz Malkani states that Material Design has not achieved a grand unification it hoped for. He concludes that it can happen only if Material Design sheds the "Google branding" and looks beyond Android.

Oct
2016

Material Design gets a new website to bring together guidelines, tools and resources in one place.

Dec
2016

Since the spec is a living document, it's frequently updated. In 2016, this is when the last of five updates to Material Design guidelines is released.

Apr
2017

Google releases Color Tool for designers working with Material Design. Designers can create new colour schemes, test accessibility and preview colours with this.

Mar
2018

Google is reportedly testing Material Design for its Search but it appears that only some users are seeing this new layout.

May
2018

At Google I/O, Google announces that designers can customize material components for their product. Tool such as Material Theme editor, icon packs and colour palettes enable this. The idea is to **separate functionality from styling** so that all apps don't end up looking the same. As an example, Google releases GMail with such a customized Material Design.

Oct
2021

Google announces that it's dropping Material Design UI components for its iOS apps in favour of Apple's UIKit. This is to save Google developers extra work in customizing Material Design to Apple's framework. Going forward, Google's iOS apps will begin to look more like iOS apps than Android apps.

Material Design


# Web Components

## Summary

A webpage can be built in two ways: either as a monolithic unit of HTML tags or as a composition of individual parts: header, footer, menu, main body, side panel, and so on. The latter is easier to maintain due to its modular nature. Such modular design has been in common practice on the server side where pages are dynamically generated from modular views. Web Components enables this on the client side.

While the use of components is possible with frameworks or libraries such as Ember, Backbone, Angular or React, Web Components is a W3C standard. It relies on nothing more than HTML, CSS and JS. It can therefore work on all browsers, can complement and be reused across frontend frameworks. Libraries built on top of Web Components are also making development simpler.

## Discussion

### What exactly is a web component?

Here's one way to define a web component,

> A component is a small, potentially re-usable set of logic, behaviors and interface elements (UI or API).

This definition is not just about the frontend element's presentation but it's also about its behaviour. Consider a clickable button. The component for this could define the styling in terms of padding, colours and fonts. It could also define the behaviour: how the styling changes on mouse hover or mouse click; what happens when mouse is clicked. Another example is an image slider. These are usually implemented using HTML, CSS, and JavaScript, all of which can be encapsulated as a custom tag for reusability.

Web Components is being developed by W3C as a set of standards. Once fully standardized and implemented by browsers, it will change the way we design web apps.

### What are the advantages of adopting Web Components?

Here are some advantages of Web Components:

    + **Reuse**: A component is made once and can be reused across different pages, apps, or frameworks.
    + **Support**: Once fully standardized, it will work on any browser without additional libraries.
    + **Maintenance**: Since the design is modular, and components are self-contained, they're easier to maintain.
    + **Encapsulation**: Each component on the same page can potentially have different styling. We need not worry about clashing element identities. This is due to what's called *Shadow DOM*.
    + **Reliability**: Code is not spread across HTML and JS files, thereby avoiding inconsistencies.
    + **Flexibility**: Components can be written inline, imported or even compiled.
    + **Composability**: Components can use or interface with other components.

### What the main parts of Web Components?

Web Components have four enabling parts:

    + **Custom Elements**: We can create custom HTML tags/elements and define their initialization and behaviour. These can be created using JavaScript APIs. The use of ES6 Class is recommended rather than create a prototype Object.
    + **HTML Templates**: Tag `<template>` provides a markup template that can then be reused in multiple places. Templates themselves are not displayed; only their instances are displayed.
    + **HTML Imports**: A HTML file can import another HTML file. Thus, components defined in one file can import components defined in another file.
    + **Shadow DOM**: This is an encapsulated DOM tree that's separate from the main document DOM. This encapsulation ensures that the component will work regardless of the page in which it's used.

### How should I use attributes, properties and events in my components?

In the spirit of reuse and composability, use attributes and properties for data input. Dispatch events for output. For example, if a button is clicked, dispatch an event so that other components can take appropriate action. Don't bubble events unless they have semantics.

Use attributes to initialize. Use properties to reflect state. Every exposed attribute should have a corresponding property. Reflecting a property change to an attribute is generally not a good idea. This is because attributes are limited to string values. This means that expensive serialization and deserialization is needed to pass arrays and objects as strings via attributes. Therefore use properties instead.

Favour declarative over imperative API. For instance, avoid changing state via method calls that don't update property or dispatch events.

### Could you share some best practices for working with Web Components?

Here are some best practices:

    + When defining custom elements, use prefixes before the hyphen to indicate a custom "namespace".
    + Custom elements that use unconventional names can be hard understand. Try to stay close to standard HTML tag names.
    + Don't raise exceptions from custom elements when for similar errors the native DOM itself would ignore and continue.
    + Configuration and state should be exposed in the logical DOM, not hidden in Shadow DOM.
    + Try to make your component self-contained without reliance on external frameworks. This makes it easy for others to reuse your component.More best practices are given at Google Developers site with illustrative examples.

### How can I use Web Components with frontend frameworks or libraries?

Web Components are set to change the way we build web apps but they need not replace frontend frameworks or libraries. The two can complement each other. For example, React can be used in Web Components or vice versa. Whereas React keeps DOM in sync with data, Web Components encapsulate reusable components well.

Use Shadow DOM to avoid conflict with frameworks that manage DOM updates and rendering. Also, VirtualDOM Abstraction Layer (VAL) gives better control over DOM along with any virtual DOM such as React or Preact.

To convert Web Components to first-class React components, react-integration can be used. Angular Elements offers custom elements but these currently have dependence on the Angular framework.

Developers who wish to develop components that can be used across any framework can look at Ionic's Stencil, SlimJS or SkakeJS. It's been said that SkateJS enables the use of React's JSX with Web Components. For data bindings, Observables and ES6 Proxies may play well with Web Components.

In passing, we mention that Accelerated Mobile Pages (AMP) are in fact built from Web Components and are incredibly performant.

### What's the current state of and browser support for Web Components?

Latest status of browser support for Web Components is available on Can I Use site. Chrome and Opera offer the best support for Web Components. Browsers that don't have full native support, can use *polyfills*. A polyfill is a substitute implementation that a developer can use or import into a codebase until browsers natively start supporting that feature or technology. Web Components polyfills are available on GitHub.

Developers can build custom components on their own. For faster development, they can also reuse components developed and shared by others as component libraries. WebComponents.org lists 1500+ reusable elements as on June 2018. Developers can also adopt component frameworks that simplify the development process. Examples of such frameworks include Google Polymer, Mozilla X-Tag and Bosonic.

In terms of W3C standardization, `<template>` element is specified within the HTML 5.2 W3C Recommendation. Shadow DOM is specified in the DOM document. Web Components Current Status page summarizes the status.

## Milestones

1998

Microsoft creates **HTML Components (HTC)** to extend the DOM with new attributes. It relies on JScript and VBScript and Microsoft ActiveX is required. In 2011, this is discontinued and deprecated on IE10.

2001

Mozilla introduces **XML Binding Language (XBL)**. The idea is to extend default tags with custom behaviour. XBL2 comes out in 2007. While the intention is good, implementations are not. This is eventually abandoned in 2012.

2010

From the failure of vendor-oriented approaches, comes the idea of frameworks or libraries that can offer custom elements in a cross-browser compatible manner. In 2010, **AngularJS** is released. Likewise, **React** is born in 2011 and is used internally by Facebook.

2011

At the Fronteers 2011 conference, Alex Russell gives a talk titled "Web Components and Model Driven Views". He explains how JS frameworks are trying to do what HTML is supposed to do. He then outlines scoped CSS, custom elements and web components.

May
2012

W3C publishes a working draft titled "Introduction to Web Components".

2014

Google Chrome and Opera browsers start supporting v0 of Web Components. In 2016, the same browsers start supporting v1 of Web Components.

Web Components


# MongoDB Sharding

## Summary

Large datasets stored on a single server can hit performance limits. One way to improve performance on a single server is to upgrade the server with higher CPU, more CPU cores, more RAM, more storage and faster I/O. This is called **vertical scaling**. It's expensive and has its limits. Sharding is a better and more scalable solution.

With sharding, large datasets are distributed across multiple machines. While each machine may not be very powerful, each one handles only a subset of the overall workload. Thus, high performance is achieved even on large datasets. This approach is called **horizontal scaling**. MongoDB does horizontal scaling via sharding.

A **shard key** is used to distribute data evenly across all shards. MongoDB can also **reshard** the data in case shards become unbalanced over time.

## Discussion

### What's the architecture of a sharded cluster in MongoDB?

Sharding is applied on a MongoDB collection, which basically consists of multiple documents. Documents of a collection are distributed across a cluster of machines or nodes. We call this a **sharded cluster**. It consists of the following components:

    + **Shard**: Each shard holds a subset of the data, that is, some documents of the collection. Each shard can be deployed as a replica set that consists of `mongod` instances.
    + **Router**: When queries are made on a collection, only relevant shards need to be queried. One or more routers, called `mongos`, perform this task. Applications should never connect directly to the shards. They should always connect via the routers.
    + **Config Server**: One or more of these store metadata and configuration settings for the cluster. Similar to the shards, config servers are replica sets.Multiple collections can share a sharded cluster. Moreover, a sharded cluster can include collections that are not sharded, that is, collections that are simply replica sets. Unsharded collections are stored on the **primary shard**. Each database has a primary shard. Even for unsharded collections, clients should connect via the router.

### What's a chunk in the context of MongoDB sharding?

A **chunk** is a contiguous range of shard key values within a particular shard. Chunk ranges include the lower boundary and exclude the upper boundary. A chunk size is by default 64 MB and can be configured in the range 1-1024 MB. If a chunk exceeds its configured size, MongoDB automatically splits it into smaller chunks. However, automatic splitting happens only when data is inserted or updated.  If necessary, manual splitting can be performed.

If data distribution becomes uneven, MongoDB's *balancer* process migrates chunks from one shard to another. From this perspective, chunk is the smallest unit of data that can be migrated. It's not possible to move just some documents of a chunk to another shard. However, it's possible to configure a chunk with a single shard key value.

It's possible to remove a shard. But before this happens, chunks from that shard are moved to other shards. This process is called **draining**.

Sometimes during incomplete migrations, a document can be present on multiple shards. This is called an **orphaned document**.

### What are the different ways to shard data into MongoDB?

MongoDB partitions a collection based on a **shard key**, which is based on one or more fields. A unique shard key value can exist in only one chunk. To shard a collection, it must have an index that starts with the shard key. This is called **shard key index**. A range of shard key values define a chunk. Each chunk is associated with one shard. Multiple chunks can reside on a shard.

MongoDB has two sharding strategies:

    + **Hashed Sharding**: Hash of the shard key value is computed. Particularly for monotonically increasing or decreasing shard key, hashed sharding distributes data more evenly. MongoDB automatically computes the hashes when querying with indexes. For a compound index, only one field can be hashed.
    + **Ranged Sharding**: Data is partitioned based on a range of shard key values. Each chunk is assigned a range.A MongoDB router queries only shards relevant to a query. In some cases, it **broadcasts** the query to all shards. Selecting a suitable shard key and sharding strategy can minimize the number of shards involved in a query.

### How do I select a suitable shard key in MongoDB?

A suitable shard key has some desirable properties:

    + **High Cardinality**: Low cardinality implies fewer unique values and hence fewer shards. For example, choosing `continent` field as the shard key limits the cluster to a maximum of seven shards. Instead, use a compound index by combining `continent` field with another field of high cardinality.
    + **Low Frequency**: Implies all documents are accessed equally. Suppose only 20% of documents are commonly accessed. This could lead to some shards getting overloaded. Chunks holding high frequency documents may grow faster, become indivisible and result in bottlenecks. Instead, use a compound index that includes a low frequency field.
    + **Grows Non-Monotonically**: If shard key increases monotonically, inserts end up in a chunk that has the `maxKey` upper bound. The shard containing this chunk presents a write bottleneck. To solve this, use hashed sharding. Another technique is that when a chunk is split, the new chunk with `maxKey` is located on another shard.
    + **Handle Common Query Patterns**: A query hits only a few shards. Common queries achieve even distribution.

### Given an uneven data distribution in a MongoDB sharded cluster, how can I correct this?

It's hard to predict how a collection will grow or how the application will evolve. The data distribution may start out evenly but may become uneven over time. Therefore there's a need to continuously improve how we shard a collection.

MongoDB 4.2 introduced **mutable shard key values**. However, the shard key itself couldn't be changed.

MongoDB 4.4 introduced **refinable shard key**. One or more fields can be suffixed to the current shard key. For example, if using `customer_id` as the shard key didn't result in an even distribution, the shard key could be refined by adding `order_id` (which has a higher cardinality). Thus, the shard key becomes `{"customer_id" : 1, "order_id": 1}`.

MongoDB 4.4 also introduced **compound hashed shard key** in which one of the fields can be hashed. A compound shard key uses more than one field. In the previous example, if `order_id` is monotonically increasing, then just adding it to the shard key will not solve our problem. Instead, the shard key can be refined to `{"customer_id" : 1, "order_id": "hashed"}`.

From MongoDB 5.0, we can simply **reshard** the collection.

### Could you explain zones and zone sharding in MongoDB?

Zones are abstractions defined based on the shard key. They help implement **data locality**. For instance, data is stored on shards geographically closer to application servers. This could be for performance or regulatory reasons. We might want to isolate a subset of data on a specific set of shards. Another reason is to route data to match hardware capabilities.

A zone can be associated with one or more shards in the cluster. A shard can associate with multiple zones. It's okay for a shard not belong to any zone. When balancing data, MongoDB migrates chunks to other shards within the zone.

A zone is defined by a range of shard key values. If hashed, range is based on the hashed values. Range includes the lower bound and excludes the upper bound. If a compound shard key is used, range definition must include the prefix field. For example, given the shard key `{ a : 1, b : 1, c : 1 }`, zone range must contain `a` field.

### Could you share some tips for data sharding in MongoDB?

If you're not sure if a collection requires sharding, you can leave it unsharded. When more data arrives, you may get a better idea about how to define the shard key and how many shards to use. It's possible to migrate from a replica set to a sharded cluster.

Suppose you observe jumbo chunks, uneven load distribution or reduced query performance over time. These are indications that the shard key is suboptimal. Either refine the key or reshard the collection.

MongoDB's *balancer* process does auto-splitting as required. In some cases, to achieve easy insertion and high write throughput, **pre-splitting** can be done to balance the distribution quickly.

Multiple routers can reduce latency but can increase load on config servers. More servers and components also leads to complexity. MongoDB Atlas, Ops Manager, Mongostat, and other tools can simplify the management.

## Milestones

Feb
2009

**MongoDB 1.0** is released. By August, this version becomes generally available for production environments.

Aug
2010

MongoDB 1.6 is released. **Sharding is now production ready**, thus making MongoDB horizontally scalable. A `mongod` instance can be upgraded to a distributed cluster without any downtime.

Aug
2012

MongoDB 2.2 is released with support for **tag-aware sharding**. For example, this can be used to ensure data is closest to application servers that use them. An improvement is that if the shard key is the prefix of existing index, there's no need to maintain a separate index.

Mar
2013

MongoDB 2.4 is released. This release supports **hashing of index**. When a hashed index is used as the shard key, this enables more even distribution of documents across shards.

Mar
2015

MongoDB 3.0 is released. Replica sets and sharded clusters can have members with **different storage engines** but performance can vary with workload.

Dec
2015

MongoDB 3.2 is released. Config servers previously used three mirrored `mongod` instances. They can now be deployed as replica sets. This means that a sharded cluster can have more than 3 (maximum 50) config servers. Master-slave replication for components of sharded cluster is deprecated. Master-slave replication is removed in MongoDB 4.0 (September 2021). Replica sets must be used instead.

Nov
2016

MongoDB 3.4 is released. We can now associate shards with one or more **zones**. Zone sharding can be considered a renaming of tag-aware sharding.

Nov
2017

MongoDB 3.6 is released. From this release, a shard can't be a standalone instance. It has to be a replica set. This ensure redundancy and high availability.

Aug
2019

MongoDB 4.2 is released. This supports **mutable shard key values**. With the exception of a shard key based on immutable `_id` field, any other shard key value is mutable.

Jul
2020

MongoDB 4.4 is released. Two new features are **refinable shard key** and **compound hashed shard key**. The latter supports zone sharding as well. These help split huge indivisible chunks due to the current shard key. Some documents may not have the shard key fields. These are treated as null values when distributing the documents but not when routing queries. The previous shard key size limit of 512 bytes is removed in this version.

Jul
2021

MongoDB 5.0 is released with support for **resharding** of a collection. This can solve the problem of uneven data distribution caused by the current shard key.

MongoDB Sharding


# OHIF Viewer

## Summary

Doctors and other medical professionals use software to view, analyse and annotate images of patients. These images could be X-rays, ultrasound/CT/PET/MRI scans, ECG/EEG waves and more. There are both commercial as well as open source viewers for this purpose. Among the open source viewers is OHIF Viewer. It's development is guided by the Open Health Imaging Foundation (OHIF).

The OHIF Viewer is configurable and extensible. It's a web application that can be used without additional software installation. It can load images from various sources or interfaces including DICOMweb. Images can be rendered in 2D, 3D or restructured representations. For authentication it supports OpenID Connect. The app is built in React using reusable UI components.

## Discussion

### Could you give an overview of OHIF Viewer?

Let's consider a radiology workflow as an example. Via CT or MRI scans of patients, images are acquired. These images are in DICOM (Digital Imaging and Communications in Medicine) format. They're sent to a DICOM router that checks the integrity of these images. From here the images are sent to Picture Archiving and Communication System (PACS) and Vendor-Neutral Archive (VNA). An example of PACS is Orthanc, a DICOM server with REST API and a web UI.

Radiologists access the images in PACS from their workstations or other devices for visualization, post-processing or analysis. Non-radiologists can access images from VNA via patient Electronic Medical Record (EMR). The figure above shows a case where this traditional workflow is being augmented with AI capabilities.

Traditional medical imaging software were often desktop applications that needed to be installed and maintained by IT staff. When problems arose, such applications were hard to debug remotely. It's in this context that web-based applications enabled by cloud computing became attractive. The OHIF Viewer is one such viewer.

### What are the main features of OHIF Viewer?

The viewer includes two essential features: visualization and annotation. For **visualization**, multi-modal image fusion, maximum intensity projection, multi-planar reformatting, axial/sagittal/coronal views, CINE view, and many more are supported. For **annotation**, there are many easy-to-use tools for measurement and annotation. Touch-specific tools such as pinch-to-zoom become handy on touchscreen devices.

In terms of software architecture and design, the viewer is built using **reusable** React UI components. This enables developers to compose more sophisticated components and custom workflows without needing to code them from scratch. Since code is open source, these components can be studied and customized as needed. The viewer is really a web application that runs within a web browser. Hence, no additional software needs to be installed to use it.

For **performance**, GPU acceleration is used for image rendering. Multi-threading enables quick image decoding.

The viewer is **standards-compliant**: DICOMweb for image data access, OpenID Connect for authorized access to data. The viewer can connect other sources as well.

For **deployment**, the viewer can be a standalone web application. Alternatively, it can be embedded via a `<script>` tag into another application but this got deprecated in version 3.

### What's the architecture of OHIF Viewer?

The OHIF Viewer adopts a modular architecture. The main platform has the following components:

    + **core**: Core libraries that implement medical imaging functions (aka business logic) for the web.
    + **i18n**: Internationalization support.
    + **viewer**: This brings together the all components. To register extensions, compose modes and route requests are its main functions.
    + **ui**: React component library.
    + **extensions**: Libraries that implement essential functionalities such as rendering, measurement tracking, etc. These are the building blocks. They're consumed by modes.
    + **modes**: A configuration to compose extensions and routes to make an application.OHIF Viewer makes use of other projects such as Cornerstone. It's a set of JavaScript libraries specific to the medical domain. Cornerstone also include libraries to load DICOM objects over the web, called WADO (Web Access to DICOM Objects). There's support for the older WADO-URI interface and the more modern WADO-RS aka DICOMweb (RESTful API). The loader uses web workers for CPU intensive image processing tasks.  It uses OpenJPEG library. Library *dcmjs* does DICOM manipulation in JavaScript.

### What are modes in OHIF Viewer?

The OHIF Viewer contains many extensions but often not all of them are needed for a specific workflow. For example, 3D segmentation has different requirements compared to tracking measurements over time. Other specific workflows are ECG viewer and total metabolic tumor volume. These different workflows are enabled via **modes**. In one sense, modes enable many mini-apps or workflows within a single app.

Modes use extensions. Modes register workflows with the viewer with certain routes. The mode will get invoked once user accesses the viewer on a registered route. Modes essentially offer a lot of flexibility to create new workflows while reusing existing extensions. Modes were introduced in version 3. In version 2 of the viewer, we had to build new UI and extensions to create new workflows.

The figure shows the composition of "AI Organ Segmentation" mode. It configures the applicable routes and extensions. It uses the applicable layout templates and data sources. Mode-specific props are passed to the templates. For each study, the viewer will show available modes. A study can have multiple modes.

### Could you do a code walkthrough of OHIF Viewer?

We describe the codebase with respect to commit beb451745 (December 2022). Paths to the components are configured in `tsconfig.json`. For example, the viewer component is at `platform/viewer/src`. At this path we find `index.js` where the application object is created. This object is inserted into the DOM at the element with ID "root". The HTML template for this is at `platform/viewer/public/html_templates/index.html`.

For interfacing to a DICOMweb server, the configuration files are at `platform/viewer/public/config` folder. Data is requested via the extension `extensions/cornerstone/src/utils/dicomLoaderServer.js`. Web workers are initialized in `extensions/cornerstone/src/initWADOImageLoader.js`.

The default mode is configured in `modes/basic-dev-mode/src/index.js`. Modes are set up for the app in `platform/viewer/src/appInit.js`.

Reusable React components are in `platform/ui/src/components`. As an example, we note that `ToolbarButton` is built from three other components, `Tooltip`, `IconButton` and `Icon`. Some extensions make use of `ToolbarButton` to compose a complete toolbar.

### What developer resources are available to work with OHIF Viewer?

The project's main website has links to documentation, examples, and more. Beginners may want to explore a demo of the software first.

The source code is available on GitHub. We can clone this code repository and build a Docker image of the viewer. Alternatively, we can use the viewer's Docker image from Docker Hub.

An easier way to use OHIF Viewer is as a cloud-based managed service. SpringML's One-Click DICOM Viewer is an example that's easily deployed on the Google Cloud. It uses Google Kubernetes Engine.

Perhaps the easiest method is to embed the viewer via a script tag into your own custom application.

OHIF Viewer is capable of invoking DICOMweb REST APIs. A cheatsheet of DICOMweb is a useful reference.

OHIF Viewer uses Cornerstone. It's a set of JavaScript libraries to display medical images, or develop tools and applications for medical imaging.

## Milestones

Sep
2015

Dr. Gordon Harris at the Massachusetts General Hospital receives **funding** for the project from a National Cancer Institute U24 grant. This funding continues till August 2020. Version 1 of the software starts life in 2015 and is active till 2019. It's uses Meteor full-stack framework. Version 1 is actually **three separate apps**: LesionTracker, OHIF Viewer, and OHIF Standalone Viewer.

2018

XNAT integrates OHIF Viewer within its environment. XNAT is a platform for quantitative imaging studies. This evolves as new versions of the viewer are released in later years: XNAT-OHIF 2.0 (2019) and XNAT-OHIF 3.2.0 (2021).  This is just one example of other projects adopting OHIF Viewer.

2019

**OHIF Viewer v2** is released. It's a single React app. It deprecates the Meteor backend. Version 2 remains in active development till 2021. The viewer's extension architecture is one of the features in this version. Others include 3D multiplanar reformatting (MPR), DICOM segmentation, and PDF visualization.

Apr
2019

Release v0.0.19 of OHIF Viewer occurs via it's code repository on GitHub. This is the first release via GitHub. **Semantic versioning** of the project starts here. In May, v0.1.0 is released. From August, each package is released separately since this is a monorepo. For example, `@ohif/core@0.11.1-alpha.8` and `@ohif/extension-cornerstone@0.0.39-alpha.8` are released in August, each with its own release numbering.

Nov
2020

**The Chan Zuckerberg Initiative** selects both OHIF and Cornerstone projects for funding. The funds would go towards better documentation, software maintenance and community outreach. Funding begins in 2021. In August 2021, the Chan Zuckerberg Initiative partners with hack.diversity to develop new training material, and provide guidance and mentorship to contributors working on these projects. This funding is renewed in 2022.

Sep
2021

**OHIF Viewer v3 Public Beta** is released. This is a departure from the Meteor-based v1 and current React-based version v2. The app is still in React but has a new UI component library that uses Tailwind CSS. Via a major re-architecture, **modes** are introduced. Extensions in v2 were hard to maintain. Modes assemble extensions via a more modular approach.

Aug
2022

At a OHIF Viewer demo and presentation, it's reported that the software will evolve to support advanced features. These include hanging protocols, volume rendering, rendering of arbitrary stack of images, rendering of colour images, videos, ECG viewer, pathology viewer, etc.

Nov
2022

**OHIF Viewer v3.3** is released. Among the new features are DICOM segmentation, multiplanar reformatting (MPR), synchronized scrolling, and reference lines. DICOM segments, rendered in 3D, are for display only and can't be edited. MPR feature uses Cornerstone3D VolumeViewports feature. Project will continue to look at bug fixes on `v2-stable` branch but will focus on `v3-stable` branch for the long term.  This release also deprecates the Embedded Viewer.

OHIF Viewer